How do I convert a single character, e.g. "a" into char

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I convert a single character, e.g. "a" into char
for use in the 'split' command?

p.s.
I have option strict on

Tia.
 
add a 'c' to denote character in your split call after your character to
split on, are you sure it's even needed though?

dim s as string = "oneatwoathreeafour"
dim values() as string = s.split("a"c)
dim morevalues() as string = s.split("a")
both produce the same results.
 
Jared said:
add a 'c' to denote character in your split call after your character to
split on, are you sure it's even needed though?

dim s as string = "oneatwoathreeafour"
dim values() as string = s.split("a"c)

yes, this worked, I like this.
dim morevalues() as string = s.split("a")

this will not work with option strict
 
Tia,
As Jared suggested use a small c, as in "a"c.

You can also use String.ToCharArray if you want to convert multiple
character string to an array of Chars.

Dim command As String
Dim delims As String = ",./"
Dim args() As String

args = command.Split(delims.ToCharArray())

Would be the same as:

args = command.Split(","c, "."c, "/"c)

However I would use the char literal ("a"c) for single characters, I've used
ToCharArray where I read the delimiters from an "external" source (such as a
parameter to the constructor, or a config file).

Hope this helps
Jay
 
Herfried,
That's true, however VS.NET changes it to a small c, so why fight it ;-)

Jay
 
Back
Top