I have a script (function) designed to remove all leading spaces from a string.Perhaps the String is not being datatyped properly, but the debugger says it is a string…
Really, Trim Ftrim or Ltrim should do this for me but are NOT WORKING AT ALL they take none of the leading spaces out… I am running 6.5.1 maybe this is the problem…
Anyway the instr in the following code returns either a 1 or a 2 when it should always send me a 1 or more than 2 since the first occurrance should be the first occurrance in a string like
" (lots of spaces not showing in posting) Using R25 - Enhanced eLearning Course"
here is the code:
Dim frstPos As Integer
Dim NewTextString As String
frstPos=Instr(1,txtString," ")
NewTextString=txtstring
While frstPos=1 Or frstPos=2
NewTextString=Right(NewTextString,Len(NewTextString)-1)
frstPos=Instr(1,NewTextString," ")
frstPos=Instr(1,NewTextString," ")
Wend
StripWhiteSpace=NewTextString
Subject: RE: Serious Problem with INSTR
The fact that all the Trim functions and Instr fail to give you the results you expect, leads me to believe that the problem is with your expectation, not with the functions. I’ve used these functions quite a bit and they all work just fine.
I suspect the problem is that what you think are leading spaces in your data, are actually some other character, perhaps tabs.
Use the DebugStr function to display the value of this string. It will display the character codes of any unusual characters in the string, e.g. “\9.” is its representation for a tab.
Subject: RE: Serious Problem with INSTR
Well, I did try to use instr(string,Chr(9)) and it did not find anything.The problem is the inconsistency.
It returns 1 OR 2 which is just plain wrong.
If the first char was a tab, then it should always return 2, or vice-versa.
I am trying it running on R6.0.1 now to see if it is a problem with my client level.
Thanks
Subject: RE: Serious Problem with INSTR
Well,6.0.1 is worse. INSTR is returning 0 for spaces.
LTrim the same.
I will try the DebugStr now.
Subject: RE: Serious Problem with INSTR
try my earlier posting…try the script in a button on a test form. See if INSTR is working at all for you. You may be right, that what you think is a text string with spaces is in fact not spaces.
I am curious.
Subject: RE: Serious Problem with INSTR
what might be in there? I am getting it from a text file with input#filenum,lintetext??
Thanks
Subject: very funny
there could be literally ANYTHING in there, starting from ASCII code 0 (which acts as a string terminator) all the way up.
Subject: RE: Serious Problem with INSTR
Andy,
I still dont understand something. Explain to me this “Returns 1 or 2” thing. For some reason, it is beyond me what you are telling us. WHAT returns 1 or 2?
Subject: RE: Serious Problem with INSTR
well,Instr (string1,string2) should return the location in string1 where string2 is found.
Like
string1=“abcde”
string2=“d”
instr(string1,string2) should return 4
Right?
well in my case I am looking for spaces in a string like
string1=“…Foo Bar” ← .'s are spaces here
so instr(string1," ") should return 1.
Right?
well for me it returns sometimes 1, sometimes 2
bummer
Subject: RE: Serious Problem with INSTR
I can’t seem to compile your debugstr function.The compiler does not know what class is LCStream.
Do I need to Include something?
Subject: RE: Serious Problem with INSTR
As that’s from the EI forum, (and the title mentions lclsx) I’d say the LC constants are from the “Lotus Connector LotusScript Extension” (lclsx.dll), so you’d need to uselsx it in (if you have it).
Subject: RE: Serious Problem with INSTR
Thanks a ton!I found that , used it and it is showing /160 for the space area.
I am looking that up.
Subject: RE: Serious Problem with INSTR
A non-breaking space – type: Alt-F1 Space Space
Subject: Serious Problem with INSTR
Andrew,
Your script works fine for me. Maybe I am missing something.
I took your script, and modified it a bit so it would run by itself…to this:
========================================
Dim frstPos As Integer
Dim NewTextString As String
Dim txtString As String
txtString = "..........................hi there" <= (dots were spaces in my script)
Dim StripWhiteSpace As String
frstPos=Instr(1,txtString," ")
NewTextString=txtstring
While frstPos=1 Or frstPos=2
NewTextString=Right(NewTextString,Len(NewTextString)-1)
frstPos=Instr(1,NewTextString," ")
frstPos=Instr(1,NewTextString," ")
Wend
StripWhiteSpace=NewTextString
Msgbox StripWhiteSpace
========================================
My messagebox shows “hi there”.
Subject: Well you also have a problem w/ your code. You are searching for 2 spaces frstPos=Instr(1,txtString," ")