This returns errors.
Error 1 Cannot implicitly convert type 'char[]' to 'char' H:\C#\stringSplit\stringSplit\Form1.cs 24 60 stringSplit Error 2 Keyword, identifier, or string expected after verbatim specifier: @ H:\C#\stringSplit\stringSplit\Form1.cs 24 59 stringSplit Error 3 Newline in constant H:\C#\stringSplit\stringSplit\Form1.cs 24 60 stringSplit Error 4 Too many characters in character literal H:\C#\stringSplit\stringSplit\Form1.cs 24 60 stringSplit Error 5 } expected H:\C#\stringSplit\stringSplit\Form1.cs 27 2 stringSplit Error 6 Invalid expression term '' H:\C#\stringSplit\stringSplit\Form1.cs 24 59 stringSplit Error 7 } expected H:\C#\stringSplit\stringSplit\Form1.cs 24 60 stringSplit Error 8 ; expected H:\C#\stringSplit\stringSplit\Form1.cs 24 66 stringSplit Error 9 { expected H:\C#\stringSplit\stringSplit\Form1.cs 24 66 stringSplit
Peter Ritchie wrote: | | String.Split will probably do what you want: String[] strings = @"1\2\3".Split(new char[] {@'\'});[/quote]
|
| |
|
| |
 |
Peter Ritchie

|
Posted: Visual C# General, How can I split text? ... treenodes |
Top |
Sorry, it was air code, try:
string[] strings = @"1\2\3".Split(new char[] {'\\'});
|
| |
|
| |
 |
Mousy

|
Posted: Visual C# General, How can I split text? ... treenodes |
Top |
string txtpath="abc/def/ghi"
string [] strArray=txtpath.Split('/');
the string strArray will contain all the splitted text
txtpath[0]-->abc
txtpath[1]-->def
txtpath[2]-->ghi
|
| |
|
| |
 |
David L

|
Posted: Visual C# General, How can I split text? ... treenodes |
Top |
The reason it doesn't work is because of the @-quoted char. @-quotation only works with strings. Try the following instead:
string [] strings = @"1\2\3".Split(new char[] { '\\' });
Did that solve it
|
| |
|
| |
 |
Michael_P2234

|
Posted: Visual C# General, How can I split text? ... treenodes |
Top |
Yep, and you have to use single quotes I guess.
|
| |
|
| |
 |
| |
|