'Returns NoFields delimited fields from record starting from StartField (first = 0)
Sub GetFields(Record As String,FieldDelim As String,StartField As Int,NoFields As Int) As String
Dim Count,SkipCount,ThisStart,StartPos As Int
Dim LastErrorMessage A string
'Determine the start position of the 1st required field
SkipCount=0
StartPos=0
Do While SkipCount < StartField
StartPos=Record.IndexOf2(FieldDelim,StartPos)+1
If StartPos=0 Then Exit
SkipCount=SkipCount+1
Loop
If SkipCount > 0 AND StartPos = 0 Then
LastErrorMessage="Error: StrUtilsLib GetFields: StartPos is past the end of the record"
Log(LastErrorMessage)
Return -1
End If
Count=0
ThisStart=StartPos
Do While Count < NoFields
ThisStart=Record.IndexOf2(FieldDelim,ThisStart)+1
If ThisStart=0 Then Exit
Count=Count+1
Loop
If ThisStart=0 Then
'No Fields Found
If Count = 0 AND NoFields > 1 AND SkipCount = 0 Then
LastErrorMessage="Error: StrUtilsLib GetFields: "&FieldDelim&" not found"
Log(LastErrorMessage)
Return -1
End If
'Last Delimeter is missing, return whole string
LastErrorMessage="Warning: StrUtilsLib GetFields: Missing last FieldDelim(s) '"&FieldDelim&"' Record returned from StartPos"
Log(LastErrorMessage)
Return Record.SubString(StartPos)
Else
Return Record.SubString2(StartPos,ThisStart)
End If
End Sub
Result = GetFields(string," ",0,3)
Dim var As String
Dim pattern As String
Dim Matcher1 As Matcher
var = " some spaces and text"
pattern = "[ ]{2,}"
Matcher1 = Regex.Matcher(pattern, var)
Do While Matcher1.Find
var = var.Replace(Matcher1.Match, " ")
Loop
Msgbox(var, "")
Hi Njdude, this not seems to works to me.You can use Regex too:
B4X:Dim var As String Dim pattern As String Dim Matcher1 As Matcher var = " some spaces and text" pattern = "[ ]{2,}" Matcher1 = Regex.Matcher(pattern, var) Do While Matcher1.Find var = var.Replace(Matcher1.Match, " ") Loop Msgbox(var, "")
Dim var As String
Dim pattern As String
Dim Matcher1 As Matcher
var = "I love basic4 android"
pattern = "[ ]{2,}"
Matcher1 = Regex.Matcher(pattern, var)
Do While Matcher1.Find
var = var.Replace(Matcher1.Match, " ")
Loop
Msgbox(var, "")
Dim words() as string
words = Regex.Split("\s", inputString)
maxWords = Min(5, words.Length)
Dim result as String = ""
for i = 0 to maxWords-1
result = result & " " & words(i)
next
How about split Regex on space?
B4X:Dim words() as string words = Regex.Split("\s", inputString) maxWords = Min(5, words.Length) Dim result as String = "" for i = 0 to maxWords-1 result = result & " " & words(i) next
SQL1.BeginTransaction
SQL1.ExecNonQuery("UPDATE Daten01 SET Feld001 = RTRIM(Feld001)")
SQL1.TransactionSuccessful
SQL1.EndTransaction
SQL1.ExecNonQuery("UPDATE Daten001 SET Feld001 = RTRIM(Feld001)")