Splicing text into characters

Hi, this might be a simple thing to do but I still need help.

How can I splice a string into individual characters including spaces?

Thank you,

Val

var s as string = "some string"
var chars() as string = s.Split( "" )

String.Split passing an empty string will do the trick
https://documentation.xojo.com/api/data_types/string.html#string-split

Edit: Beat by seconds!

If you are using 2020r1 or later take a look at the new String.Characters iterator as that should work better than Split with more complex characters such as emoji.

2 Likes

Since 2020R1: http://documentation.xojo.com/api/data_types/string.html#string-characters

Var count As Integer
For Each char As String In source.Characters
  if char = "*" then count = count + 1
Next
Return count

edit: Kudos to @kevin_g , he was 30 seconds faster

Thank you, Kem and Tim. I am thinking how to get output of the array.

I should read more about arrays and the looping.

Hi, Jeannot,

Thank you for the help and sample code. That helps a lot.

Val

1 Like

@Val_Kozmenko1 you are welcome. BTW. I’m using Xojo for almost 2 decades but bumped only today in this new feature while searching the documentation for something else … ;-).