some string.Replace () help please

Noel

Member
Licensed User
Longtime User
Hi all,

I've just stated with B4A, and till now it's fun!

Anyway... I'm stuck at the moment, and I hope that someone here might know how to solve my problem.

Basicaly I'm "scraping" some text from a website.
This is working great except one part of the text!

The html for the problem part looks like this:
B4X:
<i name=w142 class=wb>14-118</i>
<i name=w122 class=wb>10-103</i>
<i name=w1332 class=wb>99</i>
<i name=w25 class=wb>2424</i>
<i name=w346 class=wb>21</i>
The part that I'm after is between the wb> and </i>

If the w value would stay the same it would be so much easer with string.Replace("<i name=wXXX class=wb>","") and string.Replace("</i>","") but as you can see it's not.

Anyone here who might have a small example on how to do this?

Thank you,

Noel
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
Would something like this suit you?
B4X:
Dim strVar As String
strVar="<i name=w142 class=wb>14-118</i>"
strVar=strVar.SubString(strVar.IndexOf(">")+1)
strVar=strVar.SubString2(0,strVar.IndexOf("<"))
Msgbox(strVar,"")   'returns 14-118
 
Upvote 0

Spinter

Active Member
Licensed User
Longtime User
I use this code!

I use this code!

Sub Activity_Create(FirstTime As Boolean)
Dim str As String
str="<i name=w142 class=wb> 14-118 </ i>"
Dim cc As Int
Dim dd As Int
Dim str1 As String
cc =InStr(str,"wb>")
dd =InStr(str,"</")
str=str.SubString2(cc,dd)
str=str.Replace("wb>","" )
Msgbox(str,"")
End Sub


Sub InStr(StrVar As String,SearchStr As String)As Long
'*** Function by RBSoft
Dim x As Long
x = StrVar.IndexOf(SearchStr)
Return x
End Sub
 
Last edited:
Upvote 0

Noel

Member
Licensed User
Longtime User
Hello Mahares,

Thank you for your reply.

To me it looks like this will only get the needed data from the 1st line, but when the value w142 changes to w122 and so on it does not work...

Or.. Am I seeing this wrong?

Noel
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
In the first example I showed how to do the first line. If you want to do all in succession, here it is:
B4X:
Dim strVar(5) As String
strVar(0)="<i name=w142 class=wb>14-118</i>"
strVar(1)="<i name=w122 class=wb>10-103</i>"
strVar(2)="<i name=w1332 class=wb>99</i>"
strVar(3)="<i name=w25 class=wb>2424</i>"
strVar(4)="<i name=w346 class=wb>21</i>"
For i=0 To 4
   strVar(i)=strVar(i).SubString(strVar(i).IndexOf(">")+1)
   strVar(i)=strVar(i).SubString2(0,strVar(i).IndexOf("<"))
Next
Msgbox(strVar(0) & CRLF & strVar(1) & CRLF & strVar(2) & CRLF & strVar(3) & CRLF _
& strVar(4),"")
The result is: 14-118 10-103 99 2424 21
 
Upvote 0

Noel

Member
Licensed User
Longtime User
Mahares.. Yes.. Of course.
I see it now :)

I'm off testing it. Thank you (and Spinter) for your input!
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Good luck Noel. Welcome to the forum. I am still learning myself. Do not forget to declare i like this:
B4X:
Dim i as Int
 
Upvote 0
Top