[COLOR=navy][B]Sub[/B][/COLOR] [COLOR=blue]fncALLTRIM[/COLOR][B][COLOR=navy]([/COLOR][/B]xString[COLOR=navy][B])[/B][/COLOR]
[COLOR=darkgreen][B] If[/B][/COLOR] [COLOR=sienna][B]StrLength[/B][/COLOR](xString) [COLOR=red][B]<[/B][/COLOR] 1 [COLOR=darkgreen][B]Then[/B][/COLOR] [B][COLOR=sienna]Return[/COLOR][/B] ""
xs [B][COLOR=red]=[/COLOR][/B] [COLOR=blue]fncLTRIM[/COLOR](xString)
xs [B][COLOR=red]=[/COLOR][/B] [COLOR=blue]fncRTRIM[/COLOR](xs)
[COLOR=sienna][B]Return[/B][/COLOR] xs
[COLOR=navy][B]End Sub[/B][/COLOR]
[B][COLOR=#000080]Sub[/COLOR][/B] [COLOR=blue]fncLTRIM[/COLOR][B][COLOR=#000080]([/COLOR][/B]xString[B][COLOR=#000080])[/COLOR][/B]
[B][COLOR=#006400]If[/COLOR][/B] [COLOR=sienna][B]StrLength[/B][/COLOR](xString) [COLOR=red][B]<[/B][/COLOR] 1 [COLOR=darkgreen][B]Then[/B][/COLOR] [B][COLOR=sienna]Return[/COLOR][/B] ""
xs [B][COLOR=red]=[/COLOR][/B] xString
[COLOR=purple]rLTRIM[/COLOR]:
[B][COLOR=darkgreen]If[/COLOR][/B] [B][COLOR=sienna]StrLength[/COLOR][/B](xs) [B][COLOR=red]>[/COLOR][/B] 0 [COLOR=darkgreen][B]Then[/B][/COLOR]
[COLOR=darkgreen][B]If[/B][/COLOR] [COLOR=sienna][B]SubString[/B][/COLOR](xs, 0, 1) [B][COLOR=red]=[/COLOR][/B] [COLOR=sienna][B]Chr[/B][/COLOR](32) [B][COLOR=darkgreen]Then[/COLOR][/B]
xs [B][COLOR=red]=[/COLOR][/B] [B][COLOR=sienna]SubString[/COLOR][/B](xs, 1, [COLOR=sienna][B]StrLength[/B][/COLOR](xs) [B][COLOR=red]-[/COLOR][/B] 1)
[B][COLOR=sienna]Goto[/COLOR][/B] [COLOR=purple]rLTRIM[/COLOR]
[COLOR=darkgreen][B]End If[/B][/COLOR]
[B][COLOR=darkgreen]End If[/COLOR][/B]
[B][COLOR=#a0522d]Return[/COLOR][/B] xs
[B][COLOR=#000080]End Sub[/COLOR][/B]
[B][COLOR=#000080]Sub[/COLOR][/B] [COLOR=blue]fncRTRIM[/COLOR][B][COLOR=#000080]([/COLOR][/B]xString[B][COLOR=#000080])[/COLOR][/B]
[B][COLOR=#006400]If[/COLOR][/B] [COLOR=sienna][B]StrLength[/B][/COLOR](xString) [COLOR=red][B]<[/B][/COLOR] 1 [COLOR=darkgreen][B]Then[/B][/COLOR] [B][COLOR=sienna]Return[/COLOR][/B] ""
xs [B][COLOR=red]=[/COLOR][/B] xString
[COLOR=purple]rRTRIM[/COLOR]:
[B][COLOR=darkgreen]If[/COLOR][/B] [B][COLOR=sienna]StrLength[/COLOR][/B](xs) [B]>[/B] 0 Then
[COLOR=darkgreen][B]If[/B][/COLOR] [B][COLOR=sienna]SubString[/COLOR][/B](xs, [COLOR=sienna][B]StrLength[/B][/COLOR](xs) [B][COLOR=red]-[/COLOR][/B] 1, 1) [B][COLOR=red]=[/COLOR][/B] [B][COLOR=sienna]Chr[/COLOR][/B](32) [COLOR=sienna][B][COLOR=darkgreen]Then[/COLOR][/B]
[/COLOR] xs [B][COLOR=red]=[/COLOR][/B] [B][COLOR=sienna]SubString[/COLOR][/B](xs, 0, [COLOR=sienna][B]StrLength[/B][/COLOR](xs) [B][COLOR=red]-[/COLOR][/B] 1)
[B][COLOR=sienna]Goto[/COLOR][/B] [COLOR=purple]rRTRIM[/COLOR]
[COLOR=darkgreen][B]End If[/B][/COLOR]
[COLOR=sienna][B][COLOR=darkgreen]End If[/COLOR][/B]
[/COLOR][B][COLOR=#a0522d] Return[/COLOR][/B] xs
[B][COLOR=#000080]End Sub[/COLOR][/B]
Sub fncLTRIM(xString)
If StrLength(xString) < 1 Then Return ""
xs = xString
Do While StrLength(xs) > 0
If SubString(xs, 0, 1) = Chr(32) Then
xs = SubString(xs, 1, StrLength(xs) - 1)
Else
Exit
End If
Loop
Return xs
End Sub
OK - Option 2 will have to be the one!
Reading in a HTML file and stripping th markup and putting text into database - so need to strip of excess.
Thanks you for your reply.
Sub DecodeTxt(TheTxt)
tmp = ""
ch=""
leng = StrLength(TheTxt)
AON = false
For i = 0 To leng-1
ch = StrAt(TheTxt, i)
If (AON = false) Then
If (ch = "<") Then
AON = true
Else
' insert the char into text to save
tmp = tmp & ch
End If
Else
If (ch = ">") Then
AON = false
End If
End If ' else if AON is false (true)
Next
' TextConvert = LTRIM$(RTRIM$(tmp))
Return tmp
End Sub
s=" LTRIM RTRIM "
'LTRIM
lt=StrRemove (s, 0, StrIndexOf (s, StrAt(StrReplace(s," ",""),0),0))
'RTRIM
s=lt
rl=StrLength(s)
i=rl
Do While StrAt(s,i-1)=" "
i=i-1
If StrAt(s,i-1)<>" " Then Exit
Loop
rt=StrRemove(s,i,rl-i)
tvrman - here is the code I use for stripping the HTML Markup.
Pass the sub a Line of HTML
B4X:Sub DecodeTxt(TheTxt) tmp = "" ch="" leng = StrLength(TheTxt) AON = false For i = 0 To leng-1 ch = StrAt(TheTxt, i) If (AON = false) Then If (ch = "<") Then AON = true Else ' insert the char into text to save tmp = tmp & ch End If Else If (ch = ">") Then AON = false End If End If ' else if AON is false (true) Next ' TextConvert = LTRIM$(RTRIM$(tmp)) Return tmp End Sub
I have taken this from C++ which I have been using for quite a while, and converted it to B4PPC use.
[FONT=Courier New][SIZE=2][COLOR=#008000]'Regex1 is a Regex object and Match1 is a Match object.
[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]Globals
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]App_Start
Match1.New1
Regex1.New1([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"(?<=^\s*)\w.*\w|\w(?>=\s*)"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff] Msgbox[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Trim([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]" some string with spaces "[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub
[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]
Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]Trim(s)
Match1.Value = Regex1.Match(s)
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff] Return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Match1.String
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub
[/COLOR][/SIZE][/FONT]
Sub trim(txt)
ch = SubString(txt, 0, 1)
Do While Asc(ch) < 33
txt = SubString(txt, 1, StrLength(txt)-1)
ch = SubString(txt, 0, 1)
Loop
ch = SubString(txt, StrLength(txt)-1, 1)
Do While Asc(ch) < 33
txt = SubString(txt, 0, StrLength(txt)-1)
ch = SubString(txt, StrLength(txt)-1, 1)
Loop
Return txt
End Sub