Android Question [Solved]How to code converting String to a character array?

Olaan

Expert
Licensed User
Longtime User
Code: Copy
'Convert String to a character array
     Dim myChar() As Char
     For  i=0 To s.Length-1
         myChar=s.CharAt(i)
     Next


Logfile is
Cannot cast type:{Type=Char, Rank=0,RemoteObject=true}to:number
 
Last edited:
Solution
Might be better if you can post the link to that post.

I think it might be from deep in the fog of this code-porting war:
Code: Copy
' Function to get a Thai comparison string
Private Sub GetThaiComparisonString(s As String) As String
'''Dim chars() As Char = s.ToCharArray
Dim chars(s.Length) As Char
For I = 0 To s.Length - 1
    chars(I) = s.CharAt(I)
Next

It's obvious in the light of day, but at the time we were like in a swamp with alligators up our arses... 🤣
Okay, I found my answer from emexes' code.
 
Upvote 0
Might be better if you can post the link to that post.

I think it might be from deep in the fog of this code-porting war:
Code: Copy
' Function to get a Thai comparison string
Private Sub GetThaiComparisonString(s As String) As String
'''Dim chars() As Char = s.ToCharArray
Dim chars(s.Length) As Char
For I = 0 To s.Length - 1
    chars(I) = s.CharAt(I)
Next

It's obvious in the light of day, but at the time we were like in a swamp with alligators up our arses... 🤣
 
Last edited:
Upvote 0
Solution
using JavaObject

Lol where the heck is the documentation about doing that magic trick? What other secret methods and incantations are available? Does it work on other types, like Ints, Floats, Arrays, Lists?

In particular, I vaguely remember seeing some Array slicing and dicing operations that looked pretty useful, assuming I can remember them when I need them... :rolleyes:
 
Upvote 0
@emexes
the inverse
Code: Copy
    Dim a As String =  "A string with words"
    Dim b() As Char = a.As(JavaObject).RunMethod("toCharArray",Null)
    Dim d As String 
    d =  d.As(JavaObject).RunMethod("valueOf",Array(b))
    Log(d)
 
Upvote 0
@emexes: maybe we need to glue byteconverter lib to your arse for handy reference😇 bc.ToChars( s as string) as Char() plus many other useful conversions
 
Upvote 0
?
B4X: Copy
    Dim s As String = "A string with words"
    Dim a() As String = Regex.Split("", s)
   
    For Each n As Char In a
        Log(n)
    Next

1736269364688.png
 
Upvote 0
glue byteconverter lib to your arse for handy reference 😇 bc.ToChars( s as string) as Char() plus many other useful conversions

True.

If the function naming was more consistent, then I'd probably remember even without the handy reference. 🤔
 
Upvote 0
Lol where the heck is the documentation about doing that magic trick? What other secret methods and incantations are available? Does it work on other types, like Ints, Floats, Arrays, Lists?

In particular, I vaguely remember seeing some Array slicing and dicing operations that looked pretty useful, assuming I can remember them when I need them... :rolleyes:
In theory, any Android Java function should be available via JavaObject - so if you search Android Developer for what you need you should be able to work it out from there.

- Colin.
 
Upvote 0
Back
Top