|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
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)
|
|
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) > >
|
|
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) > >
|
|
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) > >
|
|
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) >> >> > >
|
|
"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
|
|
"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)
|
|
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) > >
|
|
:~( 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) >> >> > >
|
|
"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)
|
|
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) > >
|
|
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) >> >> > >
|
|
"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)
|
|
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]
|
|
"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)
|
|
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.
|
|
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.
|
|
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. > >
|
|
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. > >
|
|
|