B4A Library String Functions

Rusty

Well-Known Member
Licensed User
Longtime User
Hi Margaret, good work!
Can the Split function split a string based upon the existence of another STRING?

B4X:
dim s() as list = x.Split("Now is the time", "the")
results in an array that contains:
B4X:
s.get(0) = "Now is "
s.get(1) = " time"
Thanks in advance,
Rusty
 
Last edited:

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Margaret,
I did try it and, no, it doesn't handle it...
I had to write my own function to do so. I was hoping
Regards,
Rsuty
 

peggjones

Active Member
Licensed User
Longtime User
Functions not Working

Can anyone help me? I've added stringfunctions to my project but when I try to use a function (I've been trying with "Mid") the program won't compile. Is there anything else I need to do?

Many Thanks.
 

peggjones

Active Member
Licensed User
Longtime User
Problem with Stringfunction

I have added stringfunctions to my project. Yet when I try to use a function from it it is highlighted in red and the program won't compile. Is there anything else I need to do to enable stringfunctions.

Many Thanks
 

BvdB

Member
Licensed User
Longtime User
I have added stringfunctions to my project. Yet when I try to use a function from it it is highlighted in red and the program won't compile. Is there anything else I need to do to enable stringfunctions.

Many Thanks

I'm also new to B4A, but experienced with VB, please excuse me if I ask stupid questions in the beginning :sign0161:

I have the same experience and also get a compiler error.

I added the and selected the StringFunctions libraries as described in #1, and selected it for the project, but when I use the IsEmpty() function, I get the error: Undeclared variable 'isempty' is used before it was assigned any value.

Is there anything else I need to add or include somewhere to use the StringFunctions library?

Any help will be appreciated.
 

ValDog

Active Member
Licensed User
Longtime User
I am seeing the same problem, and I have checked StringFunctions on the IDE...
 

BvdB

Member
Licensed User
Longtime User
Have you put a check on the checkbox next to the library name on the IDE?

Yes, I added version 1.01 to the library and checked (marked) it in the library.
Attached is a screenshot, hopefully it provides sufficient info to assist me.

Thanks
 

Attachments

  • Capture.PNG
    35.6 KB · Views: 374

NJDude

Expert
Licensed User
Longtime User
Yes, I added version 1.01 to the library and checked (marked) it in the library.
Attached is a screenshot, hopefully it provides sufficient info to assist me.

Thanks

Well my friend, is not only adding and referencing the library, you have to INITIALIZE it too, you are missing something like:
B4X:
Dim sf As StringFunctions

...

If sf.IsEmpty(txtNumber) then ...
 

MattC

Member
Licensed User
Longtime User
I just know this is going to be a stupid question but I cannot figure this out so I'll ask anyway.
I have everything working fine in the main activity.
I'm now trying to use the stringfunctions in a code module and it looks like the only method that works is to dim and init the stringfunctions in every sub. I'd have expected to do this once only in a code module but using globals and process globals produced errors.
Am I missing something?
 

klaus

Expert
Licensed User
Longtime User
Sure you can!
You can define Dim sf As StringFunctions in any module in ProcessGlobals.
But to call sf from another module you must add the module name as a prefix.
Example: you Dim sf As StringFunctions in a code module named Test.
Then you can use sf in any other module with Test.sf.xxx like any other process global variable.

Best regards.
 

MattC

Member
Licensed User
Longtime User
Thank Klaus,
That's what I expected but when I try that I get this in the compile and debug window:
Compiling generated Java code. Error
B4A line: 9
sf.Initialize
javac 1.7.0_21
src\anywheresoftware\b4a\samples\httputils2\mf.java:149: error: cannot find symbol
_sf._vvv1((_ba.processBA == null ? _ba : _ba.processBA));
^
symbol: variable _ba
location: class mf
 

MattC

Member
Licensed User
Longtime User
Are you calling sf.Initialize from Sub Process_Globals?

That's what gets me the java error above.
From Globals it doesn't get dimmed or initialised at all.
I've just noticed under another code module that I cannot dim from globals there either.
What should I be doing?
Thanks for the help.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…