Android Question StringBuilder libraries

Theera

Well-Known Member
Licensed User
Longtime User
Refer to this ,Where can I get StringBuilder libraries for B4A,B4J,and B4i? Ithink B4Aversion13 there isn't thelibrary
 
Last edited:

Sagenut

Expert
Licensed User
Longtime User
StringBuilder it's a Core function.
Simply declare something like
B4X:
Dim sb as StringBuilder
and it will work in B4A, B4J and B4i.
It does not need any library to be ticked.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I B4A version13 , I search the library Under the AnywhereSoftware folder. I can't find it.
There isn't StringBuilder.jar
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I B4A version13 , I search the library Under the AnywhereSoftware folder. I can't find it.
There isn't StringBuilder.jar
There is no library for it.
It's included in the Core library that is always ticked as default.

Try writing something like in this image and you will find it in the suggestions.
I used "sb" as StringBuilder abbreviation, but you can declare the variable with any name you like of course.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Why my project still has error code?
 

Attachments

  • error.png
    6.9 KB · Views: 18
  • TestB4XStringFunctionVB2.zip
    18.6 KB · Views: 6
Upvote 0

emexes

Expert
Licensed User
Why my project still has error code?

Equivalent Core function Regex.Split works fine:
(plus note that you don't need to specify array size eg what would happen for MyTargetMoney "1.2.3" ? )

B4X:
Dim MyTargetMoney As String="1234.75"

If MyTargetMoney.Contains(".") Then
    '''Dim arrNum(2) As String =sf.Split(MyTargetMoney,".")
    Dim arrNum() As String = Regex.Split("\.", MyTargetMoney)
    
    '// บาท
    strBaht  =arrNum(0)
    '// สตางค์
    strStang= arrNum(1)

    Log(strBaht & " บาท, " & strStang & " สตางค")
End If
Log output:
Waiting for debugger to connect...
Program stared.
1234 บาท, 75 สตางค
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Close the project and open it again, then try it again
No only close the project but close computer ,it still be errored I think I will reinstall B4A again
 
Upvote 0

emexes

Expert
Licensed User
I will reinstall B4A again

Seems a bit extreme.

Did you try make your own StringBuilder library, to replace the StringBuilder that is built-in (Core) to B4X?

Maybe get rid of that first.

For what it's worth: I have both B4J and B4A installed and working, including StringBuilder, and there is no stringbuilder.jar file on any of my drives.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I'm downloading B4A, Perhaps my problemwill be solved. Thank you all of you.If it still be error.I think I try to create a small libraryfor test again.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Would you mind sending me your sourcecode. I don't understand your word "Replace the stringbuilder that is built-in(core) to B4X" how I do
What's differ between the old and the new?
 
Upvote 0

emexes

Expert
Licensed User
Would you mind sending me your sourcecode.

No worries (other than I already have). Here it is, this time:
1/ also with the B4J AppStart Sub lines around it so that you can see where it goes in the program code,
2/ leaving in the New Project "Hello World" example line, and
3/ using StringBuilder to construct the output Log line (instead of using string concatenation & operator)

edit: NO extra libraries are needed; Regex and StringBuilder are Core (built-in) objects = no need to tick anything extra in the Library Manager tab

B4X:
Sub AppStart (Args() As String)
    '''Log("Hello world!!!")
   
    Dim MyTargetMoney As String="1234.75"

    If MyTargetMoney.Contains(".") Then
        '''Dim arrNum(2) As String =sf.Split(MyTargetMoney,".")
        Dim arrNum() As String = Regex.Split("\.", MyTargetMoney)    'use Regex.Split to split one big string into smaller strings
       
        '// บาท
        strBaht  =arrNum(0)
        '// สตางค์
        strStang= arrNum(1)

        Dim sb As StringBuilder    'use StringBuilder to join many small strings into one big string
        sb.Initialize
       
        sb.Append(strBaht)
        sb.Append(" บาท, ")
        sb.Append(strStang)
        sb.Append(" สตางค")
       
        Log(sb.ToString)
    End If

End Sub
Log output:
Waiting for debugger to connect...
Program started.
1234 บาท, 75 สตางค
Program terminated (StartMessageLoop was not called).
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
I don't understand your word "Replace the stringbuilder that is built-in(core) to B4X" how I do

I agree: even I don't understand it when half of the sentence is left off.

What I wrote (asked) was:

Did you try make your own StringBuilder library, to replace the StringBuilder that is built-in (Core) to B4X?

The error message you showed us was:



which is looking for a library called stringbuilder(.jar) which is not required by and does not exist in a standard B4J or B4A installation (at least, not the ones on my computer here).

So it appears like you are trying to create a new library called stringbuilder, and confusing the B4A/B4J compiler... and me too. If you are creating a new library, give it a different name, and especially not a name that clashes with existing Core elements.

Perhaps call it NewAndImprovedStringBuilderByTheera so that it is impossible for B4A/B4J to confuse it with the built-in (Core) StringBuilder.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
If you step back one level, and describe the original problem that you are trying to solve, then we will get to the solution faster.

I think the original problem challenge objective was to split a currency amount (eg 1234.75) into its major and minor components (eg baht and satang, dollars and cents, francs and centimes, pounds and pence). Is that guess in the ballpark?
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
My target is creating B4XStringFunctionVb before order to help non-expert or man Familiarity with VB6.0 can code B4X. Therefore, it requires a command.
B4X:
Dim sf  as B4XStringFunctionVb
sf.initialize
Dim  arrNum()As String=sf.Split2(MyTargetMoney, ".")

I have just found Magret's code, there is nocode return string(), so I add it in B4XStringFunctionVb as Split2(the old code
Split return as list)

I've have the same problem.Who could helpme resolved this problem for non-expertandme, please. (waiting for sourcecode amoment)
 

Attachments

  • TestB4XStringFunctionVB2.zip
    18.6 KB · Views: 2
Last edited:
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
The function need to return an array instead of list.
Yes, I have already created Split2 addition., but I still be occured error.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…