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

    I just tested this and it works fine:

    Code:
    Dim sf As StringFunctions
    sf.Initialize
    Dim mystr As String = "N: KJ.Q63.AK743.542 AQT862.4.QJ9.T96 54.AKJT7.862.AKJ 973.9852.T5.Q873"
    mystr = sf.Stuff(mystr, 
    "R""K")
    Log(mystr)
    Results:
    The INSTR you can use is:

    Code:
    sf.InString()
     
    Last edited: Apr 9, 2014
  2. Theera

    Theera Well-Known Member Licensed User

    Hi Margret,
    I'm puzzled in condition of iif().
     

    Attached Files:

    Last edited: Apr 9, 2014
  3. sultan87

    sultan87 Active Member Licensed User

    Hello margret,

    not only the first "K" has been replaced by an "R"
    I test sf.inString

    Best Regards
     
  4. chrjak

    chrjak Active Member Licensed User

    Hi
    Use string.replace
    string = string.replace("","")
     
  5. sultan87

    sultan87 Active Member Licensed User

    Hello Margret
    thank you for String.Replace is ok
    I have a string [Dealer "N"]
    I would recovers with sf.modextract(string,X,Y) X is first " and Y is second ", the result is N
    how?
    I appreciate your help
    Best Regards
     
  6. chrjak

    chrjak Active Member Licensed User

    Ehhm i am chrjak. Not magret
     
  7. LucaMs

    LucaMs Expert Licensed User


    Maybe I did not understand it, but ...
    Code:
    Dim QUOTE As String = Chr(34)
    Dim Text As String = "[Dealer " & QUOTE &  "N" & QUOTE & "]"
    Log(Text)
    Dim Target As String = QUOTE & "N" & QUOTE
    Dim Replacement As String = QUOTE & "WHO" & QUOTE
    Text = Text.Replace(Target, Replacement)
    Log(Text)
     
  8. sultan87

    sultan87 Active Member Licensed User

    Sorry chrjak
    Thank's
     
  9. sultan87

    sultan87 Active Member Licensed User

    Hello LucaMs
    No,
    sf.modextract is used to extract text from a string to Between other blocks of text.
    my string is [Dealer "N"]
    I want to recover N
    a other example
    my string is [Vulnerable "None"]
    I want to recover None
    Best Regards
     
  10. LucaMs

    LucaMs Expert Licensed User

    My example recovers N, but I did not know the existence of the constant Quote.
    So, just remove the variable declaration.

    Code:
    Dim Text As String = "[Vulnerable " & QUOTE &  "None" & QUOTE & "]"
    Log(Text)
    Dim Target As String = QUOTE & "None" & QUOTE
    Dim Replacement As String = QUOTE & "All" & QUOTE
    Text = Text.Replace(Target, Replacement)
    Log(Text)
     
  11. sultan87

    sultan87 Active Member Licensed User

    No,
    I do not want to replace None for All
    None recover but that is between two " in the string [Vulnerable "None"]
     
  12. LucaMs

    LucaMs Expert Licensed User

    Sorry, I read "Recover" but I thought "Replace" :D

    Code:
    Dim Text As String = "[Vulnerable " & QUOTE &  "None" & QUOTE & "]"
    Dim WordRecovered As String
    Log(Text)
    Dim Q1, Q2 As Int
    Q1 = Text.IndexOf(
    QUOTE) + 1
    Q2 = Text.IndexOf2(
    QUOTE, Q1)
    WordRecovered = Text.SubString2(Q1, Q2)
    Log(WordRecovered)
     
  13. sultan87

    sultan87 Active Member Licensed User

    hello LucaMs
    thank you
    I have done the tests, it's really what I was looking
    Best regards
     
    LucaMs likes this.
  14. johnB

    johnB Active Member Licensed User

    Hi Margret,
    Unless I'm doing something wrong (most likely), is there any chance of getting this library working in B4J.
    It throws an error when I try in B4J. The library loads but I get a java error on a line number which is well outside my program.

    Looks like a great routine

    JohnB
     
  15. margret

    margret Well-Known Member Licensed User

    If you look in the B4J libraries section, there is a string functions library there just for B4J.
     
    FatalFlame likes this.
  16. johnB

    johnB Active Member Licensed User

    Hi Margret
    Thanks for your reply, sorry for my late acknowledgement.
    B4J integrates so well with B4J (despite a rocky start by me with B4J) that a different library didn't even occur to me, though obviously it should have.
    I've been working on B4A this week so haven't had the opportunity to try yet.

    Thanks again and thanks for all the good work that you and so many other do on this forum to help us dummies
     
  17. ivavilagu

    ivavilagu Member Licensed User

    I´m trying to use the library but when I declare the variable the app crashes. The log message:

    Using 1.05 version lib and 2.52 IDE version.

    I know it´s the configuration library but I'm not able to find the mistake. I also use others libs in the same project and they work well.
     

    Attached Files:

  18. margret

    margret Well-Known Member Licensed User

    If you are declaring the lib in Process Globals, try moving it to just the Globals sub. Also make sure you are not using the sf variable for something else in your code. You can also create a new test project and just load this one library and see if it works correctly, if so, we need to find the conflict.
     
  19. ivavilagu

    ivavilagu Member Licensed User

    I tested the lib with a new empty project and It doesn´t work. The "java.lang.NoClassDefFoundError" message still appears at declaration line.
     
  20. margret

    margret Well-Known Member Licensed User

    Try this sample code. If it does not work, you will need to download an older version of string functions library as you are running an older version of B4A and that may be where the issue is.

    Code:
    Sub Process_Globals
    End Sub
    Sub Globals
        
    Dim SF As StringFunctions
        SF.Initialize
    End Sub
    Sub Activity_Create(FirstTime As Boolean)
        
    Dim a As String
        a = SF.Encrypt(
    "Test Message")
        SF.MB(a)
        a = SF.Decrypt(a)
        SF.MB(a)
        
    Activity.Finish
    End Sub
    Sub Activity_Resume
    End Sub
    Sub Activity_Pause (UserClosed As Boolean)
    End Sub
     
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