Clean strings

Shay

Well-Known Member
Licensed User
Longtime User
Hi

is there easy way to clean string with none "abc" letters - meaning
if I got "Hello - Word, how are you?"
I will get "Hello World how are you" (without - , ?) etc...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Log(CleanString("Hello - World, how are you?"))
End Sub

Sub CleanString(s As String) As String
   Dim sb As StringBuilder
   sb.Initialize
   For i = 0 To s.Length - 1
      If Regex.IsMatch("[\w\s]", s.CharAt(i)) Then
         sb.Append(s.CharAt(i))
      End If
   Next
   Return sb.ToString
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…