B4A Library String Functions

Thomas Wong

Member
Licensed User
Longtime User
Hi,
Any idea how to use the Encrypt and Decrypt function in StringFunctions library?
How can I specify the salt/key for it?
I tried to search for documentation for this library but I can't find anything.

Regards,
Thomas
 

ValDog

Active Member
Licensed User
Longtime User
Margret, can you please check the DayOfMonth method? It does not seem to be working correctly.

DayOfMonth("6/17/2013"), for instance, returns a 6 ??
 

margret

Well-Known Member
Licensed User
Longtime User
Sorry, please try this new version and let me know. If all is fine I will update post #1 with this version.

Margret, can you please check the DayOfMonth method? It does not seem to be working correctly.

DayOfMonth("6/17/2013"), for instance, returns a 6 ??
 

Attachments

  • StrFunc_1.02.zip
    7.4 KB · Views: 371

PhilN

Member
Licensed User
Longtime User
You're a star! Thank you Margret for the StringsFunction library. It makes life soooooo much easier. Did I say your a star? I forget... You're a star!
 

rbsoft

Active Member
Licensed User
Longtime User
This should solve the problem:
B4X:
Sub Mid(TEXT As String, Start As Int, Length As Int) As String
    If TEXT.Length > 0 Then
        If Start + Length <= TEXT.Length Then
            Return TEXT.SubString2(Start-1, Start + Length - 1)
        End If
    End If
End Sub


Rolf
 

rbsoft

Active Member
Licensed User
Longtime User
That's what I meant, it to be changed in the library. This is the extra code I inserted into the library code.

B4X:
If Start + Length <= TEXT.Length Then
...
End If
I think Margret will take care of that, maybe she has some additional thoughts.

Rolf
 

ComposerB4A

Member
Licensed User
Longtime User
Hello, Is one question, i load que librery and set one code:

Sub Activity_Create(FirstTime As Boolean)
Msgbox(len("abc"),"")
End Sub

but not recognizes the word "len"
¿anyone know what the error is?
 

Attachments

  • NoFuncionaLaLibreria.jpg
    85.2 KB · Views: 207

NJDude

Expert
Licensed User
Longtime User
You have to initialize the library, like this for example:
B4X:
Dim sf As StringFunctions
 
...
 
Msgbox(sf.Len("abc"), "")

A separate note, why are you referencing ALL the libraries? you just need to reference the ones you will need in your project.
 

ferdztech

Member
Licensed User
Longtime User
hi @margret
i try to use the mid string function
how could i get the rest of the string without defining its length. for example the content of mystring is dynamic not constant

mystring="the quick brown fox jump over the head of the lazy dog"

In your example:

Mid (StringText As String, Start As Int, Length As Int) As String
Returns the a new String for how ever many characters passed in Length from
a starting position passed in Start.
Example:

Mid(This is a long line of text, 5, 2)
In this example the function will Return: "is"

in vb
varstring=mid$("This is a long line of text",5)
In this example the function will Return: "is a long line of text"
 

ferdztech

Member
Licensed User
Longtime User
In the next update I will add a new function that will replicate this.

That's cool, One more suggestion. Is it possible to make a function like: InStrRev as in VB

in VB for example:


mystring="the quick brown fox jump over the head of the lazy dog"

varstring= Mid$(mystring, 1, InStrRev(mystring, "fox"))

this, will return "The quick brown f"

In B4a:

I tried this way to extract string, which use two method substring2 and substring

varstring=mystring.SubString2(0,mystring.IndexOf("fox"))
varstring=varstring.SubString(varstring.IndexOf("the"))


Maybe its better ? to use your new replicate mid function and the new replicate of instrRev function to make it simple.

Thanks Again and More Power!
 

ttsolution

Member
Licensed User
Longtime User
Dear all,
I have below error while compling. Please help. Many thanks

Jonh

sf.Initialize
javac 1.7.0_07
src\b4a\example\main.java:311: error: cannot access ImplB4AClass
mostCurrent._sf._vvv1(processBA);
^
class file for anywheresoftware.b4a.B4AClass$ImplB4AClass not found
1 error
 

ralphie911

Member
Licensed User
Longtime User
Margret, thanks sop much for all your hard work. I do think I found a little bug in your MID function. While parsing bytes out of a hex string. I had to add an extra character for the last "byte" to be pulled without causing an OutOfBounds exception.

here is a code snippet:

Sub CRC16()
Dim j, nC, CRC AsInt
Dim c, hextxt AsString



hextxt = "0103000A0003 "
CRC = 0xFFFF
For nC = 1Tosf.Len(hextxt)-1Step2
j = Bit.ParseInt(sf.Mid(hextxt, nC, 2),16) 'extract hex byte
CRC = Bit.Xor(CRC, j)
Next
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…