B4A Library String Functions

margret

Well-Known Member
Licensed User
Longtime User
I just tested this and it works fine:

B4X:
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:
N: RJ.Q63.AK743.542 AQT862.4.QJ9.T96 54.AKJT7.862.AKJ 973.9852.T5.Q873

The INSTR you can use is:

B4X:
sf.InString()
 
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
Hi Margret,
I'm puzzled in condition of iif().
 

Attachments

  • MyQuestionIs.png
    7.3 KB · Views: 236
Last edited:

sultan87

Active Member
Licensed User
Longtime User
Hello margret,

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

Best Regards
 

chrjak

Active Member
Licensed User
Longtime User
Hi
Use string.replace
string = string.replace("","")
 

sultan87

Active Member
Licensed User
Longtime User
Hi
Use string.replace
string = string.replace("","")
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
 

chrjak

Active Member
Licensed User
Longtime 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
Ehhm i am chrjak. Not magret
 

LucaMs

Expert
Licensed User
Longtime 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


Maybe I did not understand it, but ...
B4X:
    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)
 

sultan87

Active Member
Licensed User
Longtime 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
 

LucaMs

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

B4X:
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)
 

sultan87

Active Member
Licensed User
Longtime User
No,
I do not want to replace None for All
None recover but that is between two " in the string [Vulnerable "None"]
 

LucaMs

Expert
Licensed User
Longtime User
Sorry, I read "Recover" but I thought "Replace"

B4X:
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)
 

johnB

Active Member
Licensed User
Longtime 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
 

johnB

Active Member
Licensed User
Longtime 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
 

ivavilagu

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

Dim sf As StringFunctions
java.lang.NoClassDefFoundError: adr.stringfunctions.stringfunctions

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.
 

Attachments

  • Captura de pantalla 2014-08-18 a la(s) 11.27.25.png
    11.6 KB · Views: 220

ivavilagu

Member
Licensed User
Longtime 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.
 

margret

Well-Known Member
Licensed User
Longtime 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.

B4X:
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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…