Group:  Microsoft Access ยป microsoft.public.access.modulescoding
Thread: Trim cr lf from string

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Trim cr lf from string
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> 06.06.2006 07:53:31
I have a string which may end in cr/lf. Or may, in fact, end in tab or any
other non-printing character. "Trim" does not remove cr/lf. Would anyone
like to suggest an optimal solution for trimming strings back to visible
characters?

(david)


Re: Trim cr lf from string
"Alex Dybenko" <alexdyb[ at ]PLEASE.cemi.NO.rssi.SPAM.ru> 06.06.2006 10:08:55
Hi,
I would try to check for asc code bigger then 32

if ask(right(str,1)) <32 then
str=left(str, len(str)-1)
end if

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:uJzBP5TiGHA.1276[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
>I have a string which may end in cr/lf. Or may, in fact, end in tab or any
>other non-printing character. "Trim" does not remove cr/lf. Would anyone
>like to suggest an optimal solution for trimming strings back to visible
>characters?
>
> (david)
>
>

Re: Trim cr lf from string
"Wayne Morgan" <comprev_gothroughthenewsgroup[ at ]hotmail.com> 06.06.2006 10:15:36
Looking at the listing in the ASCII table, you want to keep the character
only if it is between 33 and 126. If so, will the following work for you?

If Len(strString) > 0 Then
Do Until Asc(Right(strString, 1)) >= 33 and Asc(Right(strString, 1)) <=
126
strString = Left(strString, Len(strString) - 1)
Loop
End If

--
Wayne Morgan
MS Access MVP


"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:uJzBP5TiGHA.1276[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
>I have a string which may end in cr/lf. Or may, in fact, end in tab or any
>other non-printing character. "Trim" does not remove cr/lf. Would anyone
>like to suggest an optimal solution for trimming strings back to visible
>characters?
>
> (david)
>
>


Re: Trim cr lf from string
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> 06.06.2006 10:57:30
rats :~)

I was hoping for something clever using Format/StrConvert or a
form field.

:~)

(david)

"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:uJzBP5TiGHA.1276[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
>I have a string which may end in cr/lf. Or may, in fact, end in tab or any
>other non-printing character. "Trim" does not remove cr/lf. Would anyone
>like to suggest an optimal solution for trimming strings back to visible
>characters?
>
> (david)
>
>


Re: Trim cr lf from string
"Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> 06.06.2006 13:30:39
Yeah, I've had to do similar things and have yet to find anything "clever"
either. If ever I do find something, I'll be sure to share.


Rob

"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:eYZ1CgViGHA.3996[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
> rats :~)
>
> I was hoping for something clever using Format/StrConvert or a
> form field.
>
> :~)
>
> (david)
>
> "david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
> news:uJzBP5TiGHA.1276[ at ]TK2MSFTNGP03.phx.gbl...
>>I have a string which may end in cr/lf. Or may, in fact, end in tab or any
>>other non-printing character. "Trim" does not remove cr/lf. Would anyone
>>like to suggest an optimal solution for trimming strings back to visible
>>characters?
>>
>> (david)
>>
>>
>
>


Re: Trim cr lf from string
Tim Ferguson <FergusonTG[ at ]softhome.net> 06.06.2006 16:08:18
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in
news:eYZ1CgViGHA.3996[ at ]TK2MSFTNGP03.phx.gbl:

[Quoted Text]
> I was hoping for something clever using Format/StrConvert or a
> form field.
>

That's what regular expressions are for.


Tim F

Re: Trim cr lf from string
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 06.06.2006 16:08:20
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:eYZ1CgViGHA.3996[ at ]TK2MSFTNGP03.phx.gbl
[Quoted Text]
> rats :~)
>
> I was hoping for something clever using Format/StrConvert or a
> form field.

Now that you mention it ... if you have a text box on a form to work
with, you can stuff it into the control's Text property and read it back
from the Value property:

Dim s As String, t As String

s = "My String" & vbTab & vbCrLf

With Forms!Form1.Text0
.SetFocus
.Text = s
t = .Value
End With

Debug.Print Len(s), Len(t), "'" & t & "'"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Re: Trim cr lf from string
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> 07.06.2006 02:46:29
Yes!

I've pasted the bad data into a text box (that's how I got it)
then:

ctl.setfocus
ctl.text = ctl.value

:~)

Magic. Now when I append "\" to the end of the path, I get

c:\path\

instead of

c:\path
\

which is probably a valid path on an NTFS disk, but not the path I wanted.

Now if people want to have a path with an embedded cr/lf, they will have
to terminate the path section with "\"



"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> wrote in message
news:uBgWhNYiGHA.3408[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> "david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
> news:eYZ1CgViGHA.3996[ at ]TK2MSFTNGP03.phx.gbl
>> rats :~)
>>
>> I was hoping for something clever using Format/StrConvert or a
>> form field.
>
> Now that you mention it ... if you have a text box on a form to work
> with, you can stuff it into the control's Text property and read it back
> from the Value property:
>
> Dim s As String, t As String
>
> s = "My String" & vbTab & vbCrLf
>
> With Forms!Form1.Text0
> .SetFocus
> .Text = s
> t = .Value
> End With
>
> Debug.Print Len(s), Len(t), "'" & t & "'"
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>


Re: Trim cr lf from string
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> 07.06.2006 03:02:42
:~( But it doesn't work. (A2000)

(david)

"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:%23c2TVydiGHA.2456[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> Yes!
>
> I've pasted the bad data into a text box (that's how I got it)
> then:
>
> ctl.setfocus
> ctl.text = ctl.value
>
> :~)
>
> Magic. Now when I append "\" to the end of the path, I get
>
> c:\path\
>
> instead of
>
> c:\path
> \
>
> which is probably a valid path on an NTFS disk, but not the path I wanted.
>
> Now if people want to have a path with an embedded cr/lf, they will have
> to terminate the path section with "\"
>
>
>
> "Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> wrote in message
> news:uBgWhNYiGHA.3408[ at ]TK2MSFTNGP05.phx.gbl...
>> "david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
>> news:eYZ1CgViGHA.3996[ at ]TK2MSFTNGP03.phx.gbl
>>> rats :~)
>>>
>>> I was hoping for something clever using Format/StrConvert or a
>>> form field.
>>
>> Now that you mention it ... if you have a text box on a form to work
>> with, you can stuff it into the control's Text property and read it back
>> from the Value property:
>>
>> Dim s As String, t As String
>>
>> s = "My String" & vbTab & vbCrLf
>>
>> With Forms!Form1.Text0
>> .SetFocus
>> .Text = s
>> t = .Value
>> End With
>>
>> Debug.Print Len(s), Len(t), "'" & t & "'"
>>
>> --
>> Dirk Goldgar, MS Access MVP
>> www.datagnostics.com
>>
>> (please reply to the newsgroup)
>>
>>
>
>


Re: Trim cr lf from string
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 07.06.2006 04:36:15
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:u8z%23Y7diGHA.1204[ at ]TK2MSFTNGP02.phx.gbl
[Quoted Text]
> :~( But it doesn't work. (A2000)

What doesn't work, David, and how? The little code snippet I posted
worked for me -- I just tested it with Access 2000 -- so something else
must be involved.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Re: Trim cr lf from string
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> 07.06.2006 07:13:37
I pasted it into my form code, changed the control name,
put a break point just after the debug statement, and
pushed my 'ok' button.

The debug statement printed 12 12, and the text had
a line break in it -- ie, the string still had Tab
CR LF at the end, confirmed by every other way of
looking at it.

I'm using a combo box: I'll test more in the morning.

(david)



"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> wrote in message
news:%23ndNbveiGHA.4304[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
> "david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
> news:u8z%23Y7diGHA.1204[ at ]TK2MSFTNGP02.phx.gbl
>> :~( But it doesn't work. (A2000)
>
> What doesn't work, David, and how? The little code snippet I posted
> worked for me -- I just tested it with Access 2000 -- so something else
> must be involved.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>


Re: Trim cr lf from string
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> 08.06.2006 01:35:48
Works for text box, doesn't work for CBO. ~

Adding a tiny (not hidden) text box just to do
this would be a bit obscure, and I don't really want
to ditch the cbo

:~)

So it looks like it's /almost/ exactly what I was looking for

:~)

(david)



"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:ebNemHgiGHA.4512[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
>I pasted it into my form code, changed the control name,
> put a break point just after the debug statement, and
> pushed my 'ok' button.
>
> The debug statement printed 12 12, and the text had
> a line break in it -- ie, the string still had Tab
> CR LF at the end, confirmed by every other way of
> looking at it.
>
> I'm using a combo box: I'll test more in the morning.
>
> (david)
>
>
>
> "Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> wrote in message
> news:%23ndNbveiGHA.4304[ at ]TK2MSFTNGP03.phx.gbl...
>> "david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
>> news:u8z%23Y7diGHA.1204[ at ]TK2MSFTNGP02.phx.gbl
>>> :~( But it doesn't work. (A2000)
>>
>> What doesn't work, David, and how? The little code snippet I posted
>> worked for me -- I just tested it with Access 2000 -- so something else
>> must be involved.
>>
>> --
>> Dirk Goldgar, MS Access MVP
>> www.datagnostics.com
>>
>> (please reply to the newsgroup)
>>
>>
>
>


Re: Trim cr lf from string
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 08.06.2006 03:22:58
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:eFDnfvpiGHA.4660[ at ]TK2MSFTNGP03.phx.gbl
[Quoted Text]
> Works for text box, doesn't work for CBO. ~
>
> Adding a tiny (not hidden) text box just to do
> this would be a bit obscure, and I don't really want
> to ditch the cbo

Does the text box have to be visible? I wonder ...

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Re: Trim cr lf from string
Marshall Barton <marshbarton[ at ]wowway.com> 08.06.2006 04:12:09
Dirk Goldgar wrote:

[Quoted Text]
>"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
>news:eFDnfvpiGHA.4660[ at ]TK2MSFTNGP03.phx.gbl
>> Works for text box, doesn't work for CBO. ~
>>
>> Adding a tiny (not hidden) text box just to do
>> this would be a bit obscure, and I don't really want
>> to ditch the cbo
>
>Does the text box have to be visible? I wonder ...


You can't set the focus to an invisible text box.

--
Marsh
MVP [MS Access]
Re: Trim cr lf from string
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 08.06.2006 04:17:49
"Marshall Barton" <marshbarton[ at ]wowway.com> wrote in message
news:qr8f82pk7lh1c5uff8sf114ghim41ome3m[ at ]4ax.com
[Quoted Text]
> Dirk Goldgar wrote:
>
>> "david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in
>> message news:eFDnfvpiGHA.4660[ at ]TK2MSFTNGP03.phx.gbl
>>> Works for text box, doesn't work for CBO. ~
>>>
>>> Adding a tiny (not hidden) text box just to do
>>> this would be a bit obscure, and I don't really want
>>> to ditch the cbo
>>
>> Does the text box have to be visible? I wonder ...
>
> You can't set the focus to an invisible text box.

Grr, that's right. But you could use a visible text box with height and
width both = 0. That ought to work.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Re: Trim cr lf from string
John Nurick <j.mapSoN.nurick[ at ]dial.pipex.com> 08.06.2006 05:50:10
On Thu, 8 Jun 2006 00:17:49 -0400, "Dirk Goldgar"
<dg[ at ]NOdataSPAMgnostics.com> wrote:

[Quoted Text]
>Grr, that's right. But you could use a visible text box with height and
>width both = 0. That ought to work.

On Tue, 06 Jun 2006 09:08:18 -0700, Tim Ferguson
<FergusonTG[ at ]softhome.net> wrote:

>That's what regular expressions are for.

IMHO this

Dim oRE As Object 'VBScript_RegExp_55.RegExp
Set oRE = CreateObject("VBScript.Regexp")
oRE.Pattern = "\s*$"
oRE.Multiline = False

...

strTrimmed = oRE.Replace(strOriginal, "")

...

Set oRE = Nothing

is greatly preferable to a solution that involves setting the focus to a
textbox you don't want the user to know exists.


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Re: Trim cr lf from string
"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> 08.06.2006 07:42:01
Well, it's a toss up: should I have a RegExp
object i don't want the user to know exists,
or a control object I don't want the user to
know exits?


(david)


"John Nurick" <j.mapSoN.nurick[ at ]dial.pipex.com> wrote in message
news:bgef82t7dro1p11e8ileeqt3j2i3fkl9la[ at ]4ax.com...
[Quoted Text]
> On Thu, 8 Jun 2006 00:17:49 -0400, "Dirk Goldgar"
> <dg[ at ]NOdataSPAMgnostics.com> wrote:
>
>>Grr, that's right. But you could use a visible text box with height and
>>width both = 0. That ought to work.
>
> On Tue, 06 Jun 2006 09:08:18 -0700, Tim Ferguson
> <FergusonTG[ at ]softhome.net> wrote:
>
>>That's what regular expressions are for.
>
> IMHO this
>
> Dim oRE As Object 'VBScript_RegExp_55.RegExp
> Set oRE = CreateObject("VBScript.Regexp")
> oRE.Pattern = "\s*$"
> oRE.Multiline = False
>
> ...
>
> strTrimmed = oRE.Replace(strOriginal, "")
>
> ...
>
> Set oRE = Nothing
>
> is greatly preferable to a solution that involves setting the focus to a
> textbox you don't want the user to know exists.
>
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.


Re: Trim cr lf from string
"Douglas J Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> 08.06.2006 11:13:47
Well, at least with John's Late Binding example, you don't have to set a
reference to RegExp.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:u6seI8siGHA.1640[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
> Well, it's a toss up: should I have a RegExp
> object i don't want the user to know exists,
> or a control object I don't want the user to
> know exits?
>
>
> (david)
>
>
> "John Nurick" <j.mapSoN.nurick[ at ]dial.pipex.com> wrote in message
> news:bgef82t7dro1p11e8ileeqt3j2i3fkl9la[ at ]4ax.com...
> > On Thu, 8 Jun 2006 00:17:49 -0400, "Dirk Goldgar"
> > <dg[ at ]NOdataSPAMgnostics.com> wrote:
> >
> >>Grr, that's right. But you could use a visible text box with height and
> >>width both = 0. That ought to work.
> >
> > On Tue, 06 Jun 2006 09:08:18 -0700, Tim Ferguson
> > <FergusonTG[ at ]softhome.net> wrote:
> >
> >>That's what regular expressions are for.
> >
> > IMHO this
> >
> > Dim oRE As Object 'VBScript_RegExp_55.RegExp
> > Set oRE = CreateObject("VBScript.Regexp")
> > oRE.Pattern = "\s*$"
> > oRE.Multiline = False
> >
> > ...
> >
> > strTrimmed = oRE.Replace(strOriginal, "")
> >
> > ...
> >
> > Set oRE = Nothing
> >
> > is greatly preferable to a solution that involves setting the focus to a
> > textbox you don't want the user to know exists.
> >
> >
> > --
> > John Nurick [Microsoft Access MVP]
> >
> > Please respond in the newgroup and not by email.
>
>


Re: Trim cr lf from string
"Robert Morley" <rmorley[ at ]magma.ca.N0.Freak1n.sparn> 09.06.2006 18:22:30
At this point, I'd say that it's getting a little far afield. Why not
simply scan for the last character that's NOT a tab, cr, lf, or space, and
just trim the string. Anything "creative" is probably only going to confuse
any other developers that might work on this down the road, and possibly
create unnecessary overhead in your code.


Rob

"david epsom dot com dot au" <david[ at ]epsomdotcomdotau> wrote in message
news:u6seI8siGHA.1640[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
> Well, it's a toss up: should I have a RegExp
> object i don't want the user to know exists,
> or a control object I don't want the user to
> know exits?
>
>
> (david)
>
>
> "John Nurick" <j.mapSoN.nurick[ at ]dial.pipex.com> wrote in message
> news:bgef82t7dro1p11e8ileeqt3j2i3fkl9la[ at ]4ax.com...
>> On Thu, 8 Jun 2006 00:17:49 -0400, "Dirk Goldgar"
>> <dg[ at ]NOdataSPAMgnostics.com> wrote:
>>
>>>Grr, that's right. But you could use a visible text box with height and
>>>width both = 0. That ought to work.
>>
>> On Tue, 06 Jun 2006 09:08:18 -0700, Tim Ferguson
>> <FergusonTG[ at ]softhome.net> wrote:
>>
>>>That's what regular expressions are for.
>>
>> IMHO this
>>
>> Dim oRE As Object 'VBScript_RegExp_55.RegExp
>> Set oRE = CreateObject("VBScript.Regexp")
>> oRE.Pattern = "\s*$"
>> oRE.Multiline = False
>>
>> ...
>>
>> strTrimmed = oRE.Replace(strOriginal, "")
>>
>> ...
>>
>> Set oRE = Nothing
>>
>> is greatly preferable to a solution that involves setting the focus to a
>> textbox you don't want the user to know exists.
>>
>>
>> --
>> John Nurick [Microsoft Access MVP]
>>
>> Please respond in the newgroup and not by email.
>
>


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net