Android Question Problem Doing an "Split" with StringFunctions library

jlucabe

New Member
Licensed User
Longtime User
Good Morning


I have founded an bug in the method Split of the library StringFunctions found in your forum.

This bug consist on this:

When you use the Function Split to Split Strings and use this carachter
( "|" ) (ASCII 124), as a the character for separating one string into its sub-strings, the method works splitting the string into individual characters. instead of sub-strings.

NOTE: I've seen this thread:
http://www.b4x.com/android/forum/threads/stringfunctions-problem.29298/
but I think that It insn't exactly the same situation.


Thank you, Regards.
 

jlucabe

New Member
Licensed User
Longtime User
Hello again.

I've making examples using the "\|" character as the separator, and all the sub-strings generated are finished by the backslash character.

This is mi code used for testing your solution:


'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim strSource = "-1.4985018\|52.4053273\|1983688820\|node"
Dim strDivisor = "\|"
Dim result As List

Dim sf As StringFunctions


End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
result.Initialize

result = sf.Split(strSource, strDivisor)

Log (result)

End Sub

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

In the Output in the log Window of B4A I obtain this:


** Activity (main) Create, isFirst = true **


(ArrayList) [-1.4985018\, 52.4053273\, 1983688820\, node]


** Activity (main) Resume **


As you can see, the sub-strings are followed by the BackSlash Character "\"


Then, the methods Split and Split2 (I've tried with both because both are in the StringFunctions Library) have a bug because the sub-strings should be Splitted without the separator.


Thank you. Regards
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Log (result)
(ArrayList) [, -, 1, ., 4, 9, 8, 5, 0, 1, 8, ,, 5, 2, ., 4, 0, 5, 3, 2, 7, 3, ,, 1, 9, 8, 3, 6, 8, 8, 8, 2, 0, ,, n, o, d, e]
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I'll look at this code to see what I can find. Does itwork using a more common delimiter?

B4X:
Dim strSource As String = "-1.4985018,52.4053273,1983688820,node"
Dim strDivisor = ","
result.Initialize
result = sf.Split(strSource, strDivisor)
Log (result)

works as expected

(ArrayList) [-1.4985018, 52.4053273, 1983688820, node]
 
Upvote 0

derez

Expert
Licensed User
Longtime User
jlucable,
The function is OK, you are doing it wrong. Don't use
Dim strSource = "-1.4985018\|52.4053273\|1983688820\|node"
it should be
Dim strSource = "-1.4985018|52.4053273|1983688820|node"
And the split is with this: "\|"
If the source is like quoted then you need the split string like stevel05 suggested.
 
Upvote 0

pauleffect

Member
Licensed User
Longtime User
goddamn it, i was loosing my mind over this. should have known something was up with the |.
funny thing is, i tried ** at first and it also went berserk. (reworked the code since, so ... i can't vouch for this.)
 
Upvote 0
Top