Using a wildcard in replace

Dman

Active Member
Licensed User
Longtime User
I have a lot of lines of text in a label that all contain ";.?" whereas the ? is a different value in each line.

I would like to replace the space at the end with ";" to make it look like ";.?;

I have tried

B4X:
label1.text = label1.text.replace(";._", ";._;")

I thought that a wildcard was _ but it obviously isn't.

Any ideas?
 

Dman

Active Member
Licensed User
Longtime User
I think I have it figured out. The numbers after the period is 0-9 so I used this. It works but is that the correct way to do it?

For i = 0 To 9
Label1.Text = Label1.Text.Replace(":." & i,":." & i & ":")
Next
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here is another option:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim s As String = ";.1 ;.2"
   s = RegexReplace(";\.(.)", s, ";\.$1;")
   Log(s)
End Sub

Sub RegexReplace(Pattern As String, Text As String, Replacement As String) As String
    Dim m As Matcher
    m = Regex.Matcher(Pattern, Text)
    Dim r As Reflector
    r.Target = m
    Return r.RunMethod2("replaceAll", Replacement, "java.lang.String")
End Sub
 
Upvote 0
Top