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

Theera

Well-Known Member
Licensed User
Longtime User
B4X:
'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:
B4X:
' 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... 🤣

Theera

Well-Known Member
Licensed User
Longtime User
Okay, I found my answer from emexes' code.
 
Upvote 0

emexes

Expert
Licensed User
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:
B4X:
' 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

emexes

Expert
Licensed User
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

Daestrum

Expert
Licensed User
Longtime User
@emexes
the inverse
B4X:
    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

drgottjr

Expert
Licensed User
Longtime User
@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

TILogistic

Expert
Licensed User
Longtime User
?
B4X:
    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
Top