B4A Library String Functions

Discussion in 'Additional libraries, classes and official updates' started by margret, Jul 22, 2011.

  1. margret

    margret Well-Known Member Licensed 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.
     
    ralphie911 likes this.
  2. margret

    margret Well-Known Member Licensed 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.
     
    ralphie911 likes this.
  3. ttsolution

    ttsolution Member Licensed User

    My problam was solved. Many thanks Margret

    Jonh
     
  4. ralphie911

    ralphie911 Member Licensed User

    Thanks for your super quick response, You're Unbelievable :)
     
  5. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    Hello, my program goes on Error when I declare the
    Dim sf As StringFunctions
    Why? I declared it on Globals
     
  6. NJDude

    NJDude Expert Licensed User

    What's the error?
     
  7. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    The application block
     
  8. NJDude

    NJDude Expert Licensed User

    Dude, POST the error message without it we can't help you.
     
  9. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    I solved... Sorry
     
  10. NJDude

    NJDude Expert Licensed User

    This addition might be useful (to fulfill a request HERE)
    Code:
    Sub FixAndPad(Variable As String, Length As Int, Character As String, Position As StringAs 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.
    Code:
    Msgbox(FixAndPad("Hello"10"*""L"'<- This will display *****Hello
     
    Msgbox(FixAndPad("Hello"10"*""R"'<- This will display Hello*****
     
    Last edited: Sep 25, 2013
    Mashiane and fabricio like this.
  11. tucano2000

    tucano2000 Active Member Licensed User

    Thanks Margret,

    I am using split function in my project.

    What the lowest api level to this library ?
     
    Last edited: Jan 2, 2014
  12. alanyu

    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 ... "


     
  13. margret

    margret Well-Known Member Licensed User

    This code should work. I will have to add this to the library when I get time.

    Code:
    'Call Like Below:
    'MyAnswer = GetStrBlock("aaa .... [ bbb ... ] ccc ...", "[", "]")
    Sub GetStrBlocK(Text As String, StartChar As String, EndChar As StringAs 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
     
  14. stanks

    stanks Active Member Licensed User

    little fix (page 1)....SplitGetWord example will return "is" and note test
     
  15. margret

    margret Well-Known Member Licensed User

    Which version are you using? I would like to check this.
     
  16. margret

    margret Well-Known Member Licensed User

    I just ran this test code in the latest version and it returns the word "is", which is the second word and the correct one. So this is working as it should.

    Code:
    Dim sf As StringFunctions
    sf.Initialize
    Dim ans As String = sf.SplitGetWord("This is a test string."" "2)
    Log(ans)
     
    Theera likes this.
  17. margret

    margret Well-Known Member Licensed User

    New Version 1.05 online. See first post for new functions/commands and to download 1.05, Click Here
     
  18. Beja

    Beja Expert Licensed User

    Thank you Margret for the useful library.

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

    Beja Expert Licensed User

    Sorry.. just found it listed on the first post.. how am I thinking!
     
  20. NJDude

    NJDude Expert Licensed 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: Mar 14, 2014
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice