Android Question substring handling

notedop

Member
Licensed User
Longtime User
Hi,
I need to create substrings, do some checks based on these strings and then recalculate something.
I'm a bit stuck with the string conversion.
The input is an list containing 2 lists looks as following:
B4X:
(ArrayList) [[D+_bl ; a+/D+_bl+ ; a, D+_bl ; a+/D+_bl+ ; a+, D+_bl+ ; a+/D+_bl+ ; a, D+_bl+ ; a+/D+_bl+ ; a+, D_bl ; a+/D+_bl+ ; a, D_bl ; a+/D+_bl+ ; a+, D_bl+ ; a+/D+_bl+ ; a, D_bl+ ; a+/D+_bl+ ; a+], [21.5, 21.5, 3.5, 3.5, 3.5, 3.5, 21.5, 21.5]]
We have D+_bl ; a+/D+_bl+ ; a as the first string
This needs to be split into 2 strings, everything before / and everything after /.
then the string needs to be split on ; sign
Then the string needs to be split on _ sign, if available.
I have the following code, but it seems that the regex.split function does not add the split strings to the list as a string.

what am I missing?
B4X:
Sub convert_mut_string( input As List) As List
Dim output As List
Dim mutstring As List
Dim mutpercent As List
output.Initialize
mutstring.Initialize
mutpercent.Initialize
 
mutstring = input.Get(0)
mutpercent = input.Get(1)
For Each S As String In mutstring
Dim b, b2, b3, b4, b5 As List  'buffers
b.Initialize 'used for
b2.Initialize
b3.Initialize
 
b.AddAll(Regex.Split("/", S))  'result can only be 2 strings.
 
b2.AddAll( Regex.Split("_", Regex.Split(" ; ", b.Get(0)))) 'this is everything before the / sign
b3.AddAll( Regex.Split("_", Regex.Split(" ; ", b.Get(1)))) 'this is everything after the / sign
 
Log(b2)
Msgbox(b2, "Output")
Log(b3)
Msgbox(b3, "Output")
'loop through both lists and create new textstring
 
For i =0  To b2.Size -1
Log (b2.Get(i) &"/"&  b3.Get(i))
Select check_visual(b2.Get(i), b3.Get(i)) 'true for visual/DF, false for split/SF, none for Not mutated, intermediate for recombinations
Case "true"
Case "false"
Case "none"
Case "intermediate"
End Select
Next
 
Next
End Sub

logfile output, instead of (ArrayList) [[Ljava.lang.String;@4501fed0] I was expecting to see a substring.

B4X:
(ArrayList) [[D+_bl*tq/D+_bl+, D+_bl+/D+_bl+, D_bl*tq/D+_bl+, D_bl+/D+_bl+], [7.0, 43.0, 43.0, 7.0]]
(ArrayList) [[Ljava.lang.String;@4500c038]
(ArrayList) [[Ljava.lang.String;@4500c760]
[Ljava.lang.String;@4500c038/[Ljava.lang.String;@4500c760
(ArrayList) [[Ljava.lang.String;@4501fed0]
(ArrayList) [[Ljava.lang.String;@450204e0]
[Ljava.lang.String;@4501fed0/[Ljava.lang.String;@450204e0
(ArrayList) [[Ljava.lang.String;@4504c1e8]
(ArrayList) [[Ljava.lang.String;@4504c7e8]
[Ljava.lang.String;@4504c1e8/[Ljava.lang.String;@4504c7e8
(ArrayList) [[Ljava.lang.String;@44fb15e8]
(ArrayList) [[Ljava.lang.String;@44fa2620]
[Ljava.lang.String;@44fb15e8/[Ljava.lang.String;@44fa2620
can someone please help me?
 

notedop

Member
Licensed User
Longtime User
okay, should not use b2.addall when adding an array. Instead just b2 =

B4X:
Sub convert_mut_string( input As List) As List
Dim output As List
Dim mutstring As List
Dim mutpercent As List
output.Initialize
mutstring.Initialize
mutpercent.Initialize

mutstring = input.Get(0)
mutpercent = input.Get(1)
For Each S As String In mutstring
 Dim b, b2, b3, c2, c3, d2,d3 As List  'buffers
 b.Initialize 'used for 
 b2.Initialize
 b3.Initialize
 c2.Initialize
 c3.Initialize
 d2.Initialize
 d3.Initialize
 
 b = Regex.Split("/", S)  'result can only be 2 strings.
 
 b2 = Regex.Split(" ; ", b.Get(0)) 'this is everything before the / sign
 b3 = Regex.Split(" ; ", b.Get(1))  'this is everything after the / sign
 
 'first look through list and split each object into another list and then loop through that list again to add it to D2
 For j=0 To b2.Size -1
 Dim c2 As List
 c2 = Regex.Split("_", b2.Get(j))
 For k=0 To c2.Size-1
 d2.Add(c2.Get(k))
 Next
 Next
 
 For j=0 To b3.Size -1
 Dim c3 As List
 c3 = Regex.Split("_", b3.Get(j))
 For k=0 To c3.Size-1
 d3.Add(c3.Get(k))
 Next
 Next
 
 Log(d2)
 Log(d3)
 'loop through both lists and create new textstring
 For i =0  To d2.Size -1
 Log (d2.Get(i) &"/"&  d3.Get(i))
 Select check_visual(d2.Get(i), d3.Get(i)) 'true for visual/DF, false for split/SF, none for Not mutated, intermediate for recombinations
 Case "true" 'visual
 
 Case "false"
 Case "none"
 Case "intermediate"
 End Select
 Next 
 
Next
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
If I were you,I must use Magret's StringFunction Library for string management.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…