ra7en
New Member
Posts: 7
|
Post by ra7en on Sept 24, 2023 15:01:04 GMT
Hi, OK so did some rework, and found that it was the way it was pulling it from the messy original text file. I actually cleaned up the line first, taking out any hashes, symbols etc.. however, you are right, there was a chr$(0) preceding it, that I never saw. N++ allowed me to view it, so a simple ctrl-h did the trick and eliminated it. still though, string manipulation is tricky with qb64. wish it had a "replace" "remove" function for removing substrings from strings, I used php heavily so str_replace works like magic LOL. but it is "basic" LOL.
thanks for the chr$(0) tip. text file is cleaned up now.
ps I think I am under Dark4ngel under the old forum...
|
|
|
Post by bplus on Sept 24, 2023 16:56:51 GMT
Hey have I a Function for you!
s$ = "The rain in Spain falls plainly in vain." Print strReplace$(s$, "ain", "at", 1) Print strReplace$(s$, "ain", "at", 0) Print strReplace$(s$, "ain", "", 0) ' removing ain
Function strReplace$ (s$, replace$, new$, FirstOnlyTF) 'case sensitive 2022-10-14 FirstOnly Parameter Dim p As Long, sCopy$, LR As Long, lNew As Long If Len(s$) = 0 Or Len(replace$) = 0 Then strReplace$ = s$: Exit Function Else LR = Len(replace$): lNew = Len(new$) End If
sCopy$ = s$ ' otherwise s$ would get changed p = InStr(sCopy$, replace$) While p sCopy$ = Mid$(sCopy$, 1, p - 1) + new$ + Mid$(sCopy$, p + LR) If FirstOnlyTF Then strReplace$ = sCopy$: Exit Function p = InStr(p + lNew, sCopy$, replace$) Wend strReplace$ = sCopy$ End Function
Extremely handy, keep in your toolbox! You can use it for removal set new$ = "" just added that to demo.
|
|
|
Post by bplus on Sept 24, 2023 17:02:42 GMT
Oh another thought, why didn't instr(aline, "Leave") >=1 catch Leave? Maybe Instr() can't detect a Chr$(0), makes sense. Who can catch nutt'n? ;-))
|
|