Android Question [Solved] What function is similar to SplitGetWord in the StringFunctions lib?

asales

Expert
Licensed User
Longtime User
There are the library StringFunctions:
https://www.b4x.com/android/help/stringfunctions.html#stringfunctions_splitgetword

and there are this observation of Erel:
https://www.b4x.com/android/forum/threads/b4x-text-strings-and-parsers.83510/#content
A relatively popular library named StringFunctions is available. It was written by @margret.
I don't recommend using it as it is not maintained and all its features are already available in the core library.


The SplitGetWord returns just the one element selected with GetElement from the string.
Example:
B4X:
ANS = SF.SplitGetWord("This is a test string.", " ", 2)
In this example the function will Return: "is"

How I can do this using the feature of the core library?

Thanks in advance for any tips.
 

klaus

Expert
Licensed User
Longtime User
This sub does what you want.
The difference is that the index begins with 0 not with 1 like in your example.
To get 'is', you should use ANS = SplitGetWord("This is a test string.", " ", 1)

B4X:
Sub SplitGetWord(txt As String, SplitCharacter As String, Index As Int) As String
    Private words() As String
    
    words = Regex.Split(SplitCharacter, txt)
    Return words(Index)
End Sub
 
Upvote 0
Top