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

Theera

Expert
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

Expert
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

emexes

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

Computersmith64

Well-Known Member
Licensed User
Longtime User
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
Top