B4A Library String Functions

margret

Well-Known Member
Licensed User
Longtime User


Please post a sample project and I will be glad to check it. You don't show it, but did you also Dim the object? Also, try to compile in Release mode only.
 

margret

Well-Known Member
Licensed User
Longtime User

It was a bug. I have updated and corrected this. It is attached to post #1 of this thread as Version 1.04. Please let me know if you find any other issues.
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello, my program goes on Error when I declare the
Dim sf As StringFunctions
Why? I declared it on Globals
 

NJDude

Expert
Licensed User
Longtime User
This addition might be useful (to fulfill a request HERE)
B4X:
Sub FixAndPad(Variable As String, Length As Int, Character As String, Position As String) As String
 
    Dim Padding As String
 
    Length = Abs(Length)
 
    If Character.Length = 0 Then Character = " " 
    If Position.Length = 0 Then Position = "R"
 
    For I = 0 To Length
 
        Padding = Padding & Character
 
    Next
 
    If Position = "R" Then
 
       Variable = Variable & Padding 
       Variable = Variable.SubString2(0, Length)
 
    Else
 
       Variable = Padding & Variable 
       Variable = Variable.SubString2(Variable.Length - Length, Variable.Length)
 
    End If
 
    Return Variable
 
End Sub
This function will fix the size of the string and pad it with any character, e.g.
B4X:
Msgbox(FixAndPad("Hello", 10, "*", "L") '<- This will display *****Hello
 
Msgbox(FixAndPad("Hello", 10, "*", "R") '<- This will display Hello*****
 
Last edited:

tucano2000

Active Member
Licensed User
Longtime User
Thanks Margret,

I am using split function in my project.

What the lowest api level to this library ?
 
Last edited:

alanyu

Member
Licensed User
I have a string, "aaa .... [ bbb ... ] ccc ..."
How to get"bbb..."
Can you add the following features?

Mid (StringText As String, Start As String, Length As String) As String

Example:

Mid("aaa .... [bbb ... ] ccc ...", "[", "]")
In this example the function will Return: "bbb ... "


 

margret

Well-Known Member
Licensed User
Longtime User
This code should work. I will have to add this to the library when I get time.

B4X:
'Call Like Below:
'MyAnswer = GetStrBlock("aaa .... [ bbb ... ] ccc ...", "[", "]")
Sub GetStrBlocK(Text As String, StartChar As String, EndChar As String) As String
     Dim s As StringFunctions : s.Initialize
     Dim a = Text As String
     Dim ans As String
     ans = s.Left(a, s.At(a, EndChar))
     ans = s.Trim(s.Right(ans, s.At(ans, StartChar)))
     Return ans
End Sub
 

stanks

Active Member
Licensed User
Longtime User
little fix (page 1)....SplitGetWord example will return "is" and note test
 

Beja

Expert
Licensed User
Longtime User
Thank you Margret for the useful library.

Where can I find the text of the functions? I just downloaded the 2 lib files.
 

Beja

Expert
Licensed User
Longtime User
Sorry.. just found it listed on the first post.. how am I thinking!
 

NJDude

Expert
Licensed User
Longtime User
You have a few typos on the tooltips:

1- You need to correct the tooltip for MID, the sample you have is missing quotes, that might confuse the newbies.

2- You have typed "negitive" instead of Negative in NewDate

3- You have "lendth" instead of Length in PAD

4- On StrArraySort you have misspelled Ascending, you have entered "Accending"

5- On TRIM, you have "will" instead of With

Nice lib, keep up the good work.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…