J jlucabe New Member Licensed User Longtime User Mar 7, 2014 #1 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Mar 7, 2014 #2 I'm not familiar with the implementation of StringFunctions. However if it is based on Regex.Split then the separator is a regular expressions string. This means that you need to escape the pipe character: Code: "\|" Upvote 0
I'm not familiar with the implementation of StringFunctions. However if it is based on Regex.Split then the separator is a regular expressions string. This means that you need to escape the pipe character: Code: "\|"
J jlucabe New Member Licensed User Longtime User Mar 7, 2014 #3 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
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
margret Well-Known Member Licensed User Longtime User Mar 7, 2014 #4 What happens if you use the pipe character without the backslash. What do the logs show then? Upvote 0
DonManfred Expert Licensed User Longtime User Mar 7, 2014 #5 Code: 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] Click to expand... Last edited: Mar 7, 2014 Upvote 0
Code: 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] Click to expand...
margret Well-Known Member Licensed User Longtime User Mar 7, 2014 #6 I'll look at this code to see what I can find. Does it work using a more common delimiter? Last edited: Mar 7, 2014 Upvote 0
DonManfred Expert Licensed User Longtime User Mar 7, 2014 #7 margret said: I'll look at this code to see what I can find. Does itwork using a more common delimiter? Click to expand... Code: 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] Click to expand... Upvote 0
margret said: I'll look at this code to see what I can find. Does itwork using a more common delimiter? Click to expand... Code: 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] Click to expand...
margret Well-Known Member Licensed User Longtime User Mar 7, 2014 #8 Yes, you can use "/" or "," but not "\" or "|". I am calling a core function and it performs the same way, so this is past what I can change, sorry. Upvote 0
Yes, you can use "/" or "," but not "\" or "|". I am calling a core function and it performs the same way, so this is past what I can change, sorry.
DonManfred Expert Licensed User Longtime User Mar 7, 2014 #9 I´m not @jlucabe - the thread opener - but i will thank you for your answer. I must burn that into my brain cause i dont want to run into this trap ;-) Upvote 0
I´m not @jlucabe - the thread opener - but i will thank you for your answer. I must burn that into my brain cause i dont want to run into this trap ;-)
derez Expert Licensed User Longtime User Mar 7, 2014 #11 jlucable, The function is OK, you are doing it wrong. Don't use Dim strSource = "-1.4985018\|52.4053273\|1983688820\|node" Click to expand... 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
jlucable, The function is OK, you are doing it wrong. Don't use Dim strSource = "-1.4985018\|52.4053273\|1983688820\|node" Click to expand... 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.
margret Well-Known Member Licensed User Longtime User Mar 7, 2014 #12 @derez Thank You !! Derez's answer is confirmed and works fine. Upvote 0
J jlucabe New Member Licensed User Longtime User Mar 10, 2014 #13 Thank you for your posts @Erel @margret @DonManfred @stevel05 @derez You´ve all helped me to ubderstand the use of this function in this library. Thank you so much. My best regards. Upvote 0
Thank you for your posts @Erel @margret @DonManfred @stevel05 @derez You´ve all helped me to ubderstand the use of this function in this library. Thank you so much. My best regards.
pauleffect Member Licensed User Longtime User Mar 21, 2014 #14 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
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.)