B4J Library JStringFunctions Beta

Here is the B4A StringFunctions library, converted to B4J. This is a Beta version and I am looking for feedback and testing. I don't expect all this will be working this first try. I just started in B4J a few days ago. The one known issue is the MB() function will not work but there may be others as well. Any feedback or help testing would be great. See the B4A StringFunctions Library in my signature for the docs.
 

Attachments

  • JStringFunctions.zip
    7.6 KB · Views: 1,489

Theera

Well-Known Member
Licensed User
Longtime User
Thank you ,Margret. I promise myself ,I will use your library to be worthwhile.
 

giouti

New Member
Licensed User
Longtime User
Hello Margret,
I was doing some quick tests today with a calculator program (written in B4A and modified for B4J). The Left() & Len() functions are working fine.
The "initialize" function on my system works if written exactly as in B4A(with no parameters):
Dim sf As JStringFunctions
sf.Initialize
If I write it as indicated in the docs(http://www.b4x.com/b4j/help/jstringfunctions.html#jstringfunctions_initialize), I get back an error during compilation: "Error description: Array expected."

Thank you, have a great day !
Giorgio
 

margret

Well-Known Member
Licensed User
Longtime User
I am working on a new version that does need the parameter passed in the Initialize command. However, I have not posted it yet so I am a little puzzled how the docs have this change. You are correct the current version has no parameters to pass. I will check into this and see if I can find how the docs were updated before the release. Thank You.
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Just what I need thanks Margret;););):)
 

jmon

Well-Known Member
Licensed User
Longtime User
Great functions. Could it be possible to save the library as a code module instead of a class? That way you wouldn't need the initialize function.

May I suggest a few ones that you could add?:
B4X:
'Trims n letters from the right side of the string.
Public Sub TrimRight(s As String, amnt As Int) As String
    If amnt > s.Length Then Return s
    Return s.SubString2(0, s.Length - 1 - amnt)
End Sub  

'Trims n letters from the left side of the string.
Public Sub TrimLeft(s As String, amnt As Int) As String
    If amnt > s.Length Then Return s
    Return s.SubString2(amnt, s.Length)
End Sub  

'Repeats n times the given string.
Public Sub Repeat(Text As String, nTimes As Int) As String
    Dim s As StringBuilder : s.Initialize
    For i = 1 To nTimes
        s.Append(Text)
    Next
    Return s.ToString
End Sub  

'Counts the number of times the text is present in the string.
Public Sub CountOccurence(Text As String, Character As String) As Int
    Dim i As Int = 0
    Dim index As Int = -1
    Do While True
        index = Text.IndexOf2(Character, index +1)
        If index = -1 Then Exit
        i = i +1
    Loop
    Return i
End Sub

'Returns true if the regular expression is present in the string.
Public Sub ContainsRegex(Pattern As String, Text As String, CaseSensitive As Boolean) As Boolean
    Dim m As Matcher
    If CaseSensitive Then
        m = Regex.Matcher(Pattern, Text)
    Else
        m = Regex.Matcher2(Pattern, Regex.CASE_INSENSITIVE, Text)
    End If
    Return m.Find
End Sub
 

Bruce Axtens

Active Member
Licensed User
Longtime User
Thanks Margret.

A request. Could Mid() be permitted to have an optional final parameter which, if not specified, defaults to the length of the string?

Also

Please could we have a Replace function (unless it's been done elsewhere and I haven't found it yet)

Kind regards,
Bruce.
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Replace is easy to do see code
B4X:
Dim str As String
str = "abcdefghij"
str = str.Replace("abc", "xyz")
 

Bruce Axtens

Active Member
Licensed User
Longtime User
Thank you!
 

JTmartins

Active Member
Licensed User
Longtime User
HI,

How does the AsciiCodes function works ? Could not understand.

Many thanks.
 

Reinierus

Member
Licensed User
Longtime User
Hello.
I am trying this code:
B4X:
vrCCMulti=vrCursor.GetString("CC")
    vrCCInicio=1
    For i=1 To StringFuncion.Len(vrCCMulti)
            vrCCCaracter=StringFuncion.Mid(vrCCMulti,i,1)
            If vrCCCaracter=";" Then
                Log(vrCCInicio)
                vrDirecCC=StringFuncion.Mid(vrCCMulti,vrCCInicio,i-1)
                Log(vrDirecCC)
                vrSMTP.CC.Add(vrDirecCC)
                vrCCInicio=i+1
            End If
    Next
Where vrCCMulti = "[email protected]; [email protected]; [email protected]"

The idea is to get each email address, but I get:

What I am doing wrong?

Please help

Thanks a lot
 
Top