1 liner for String.Split 
November 21st, 2008, 02:15 AM
| | | |
in regards to parsing directories..
Dim Sep(0) as char
Sep(0) = "\"
Dim Parts() as string = Filename.Split(Sep)
What I want is to declare a temporary variable that is passed to split directly.
Tried a few ways, none work...
Any ideas? | 
November 21st, 2008, 02:55 AM
| | | | re: 1 liner for String.Split
Robert wrote: Quote:
in regards to parsing directories..
>
Dim Sep(0) as char
Sep(0) = "\"
Dim Parts() as string = Filename.Split(Sep)
>
>
What I want is to declare a temporary variable that is passed to split directly.
>
Tried a few ways, none work...
>
Any ideas?
>
>
| I'm not really sure what you're asking, but is this what you want? -
Dim Parts() As String = Filename.Split("\"c)
ShaneO
There are 10 kinds of people - Those who understand Binary and those who
don't. | 
November 21st, 2008, 03:05 AM
| | | | re: 1 liner for String.Split
"Robert" <no@spam.comwrote in message
news:ODQ%23C53SJHA.5268@TK2MSFTNGP04.phx.gbl... Quote:
in regards to parsing directories..
>
Dim Sep(0) as char
Sep(0) = "\"
Dim Parts() as string = Filename.Split(Sep)
>
>
What I want is to declare a temporary variable that is passed to split
directly.
>
Tried a few ways, none work...
>
Any ideas?
>
|
I would do it this way instead:
Dim Parts() As String =
Filename.Split(System.IO.Path.DirectorySeparatorCh ar) | 
November 21st, 2008, 05:15 AM
| | | | re: 1 liner for String.Split
> Quote:
Dim Sep(0) as char
Sep(0) = "\"
Dim Parts() as string = Filename.Split(Sep)
>
>
What I want is to declare a temporary variable that is passed to split
directly.
>
Tried a few ways, none work...
>
| If its VB, why not just use the Split function instead of the split method
of the String class.
Dim Parts() as String = split(Filename, "\") | 
November 21st, 2008, 06:15 AM
| | | | re: 1 liner for String.Split
Robert wrote: Quote:
in regards to parsing directories..
>
Dim Sep(0) as char
Sep(0) = "\"
Dim Parts() as string = Filename.Split(Sep)
>
>
What I want is to declare a temporary variable that is passed to split directly.
>
Tried a few ways, none work...
>
Any ideas?
>
>
| Here you go:
Dim Parts() As String = Filename.Split(New Char() {"\"c})
--
Teme64 @ http://windevblog.blogspot.com | 
November 21st, 2008, 07:25 AM
| | | | re: 1 liner for String.Split
>Dim Sep(0) as char Quote: Quote:
>Sep(0) = "\"
>Dim Parts() as string = Filename.Split(Sep)
| >
>
Dim Parts() As String = Filename.Split(New Char() {"\"c})
| Ding, Ding! We have a winner.
First, it must be a char array or a string array.
Second using the VisualBasic namespace is just not something I do ever since a large PocketPC port.
The name space does not exist there.
Third, I swear I tried the above, but without the New!
Now, why the new? Because that makes it work, DUH, got that.
but in my example above, new is not needed..
Thanks a bunch for saving some useless filler lines. Conciseness is important. | 
November 21st, 2008, 01:35 PM
| | | | re: 1 liner for String.Split
"Robert" <no@spam.comwrote in message
news:eF4M7k6SJHA.5408@TK2MSFTNGP04.phx.gbl... Quote: Quote: Quote:
>>Dim Sep(0) as char
>>Sep(0) = "\"
>>Dim Parts() as string = Filename.Split(Sep)
| >>
>>
>Dim Parts() As String = Filename.Split(New Char() {"\"c})
| >
Ding, Ding! We have a winner.
>
First, it must be a char array or a string array.
Second using the VisualBasic namespace is just not something I do ever
since a large PocketPC port.
The name space does not exist there.
>
Third, I swear I tried the above, but without the New!
>
Now, why the new? Because that makes it work, DUH, got that.
but in my example above, new is not needed..
>
Thanks a bunch for saving some useless filler lines. Conciseness is
important.
>
|
OK, but calling split with a single character does work. I see that the
documentation says it must be an array. There must be a conversion to an
array as all of the single character versions posted work fine for me. | 
November 21st, 2008, 11:05 PM
| | | | re: 1 liner for String.Split
"Family Tree Mike" <FamilyTreeMike@ThisOldHouse.comschrieb: Quote: Quote:
>First, it must be a char array or a string array.
>Second using the VisualBasic namespace is just not something I do ever
>since a large PocketPC port.
>The name space does not exist there.
>>
>Third, I swear I tried the above, but without the New!
| [...]
OK, but calling split with a single character does work. I see that the
documentation says it must be an array. There must be a conversion to an
array as all of the single character versions posted work fine for me.
| Just use '... = s.Split("/"c)'. The parameter is actually a parameter array
('ParamArray'), which allows multiple ways of calling:
* '... = s.Split(New Char() {"a"c, "b"c})'
* '... = s.Split("a"c, "b"c)'
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/> | 
November 22nd, 2008, 01:25 AM
| | | | re: 1 liner for String.Split
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrote in message news:eBF8jyCTJHA.1960@TK2MSFTNGP04.phx.gbl... Quote:
"Family Tree Mike" <FamilyTreeMike@ThisOldHouse.comschrieb: Quote: Quote:
>>First, it must be a char array or a string array.
>>Second using the VisualBasic namespace is just not something I do ever since a large PocketPC port.
>>The name space does not exist there.
>>>
>>Third, I swear I tried the above, but without the New!
| >[...]
>OK, but calling split with a single character does work. I see that the documentation says it must be an array.
>There must be a conversion to an array as all of the single character versions posted work fine for me.
| >
Just use '... = s.Split("/"c)'. The parameter is actually a parameter array ('ParamArray'), which allows multiple
ways of calling:
>
* '... = s.Split(New Char() {"a"c, "b"c})'
* '... = s.Split("a"c, "b"c)'
|
I tried at least 5 different permutations on this. None worked...
Then with the new VB with {} I poked around some more thinking, oooh declare and
initialize in one shot! Can remove some useless lines. Still nothing..
not sure where I got distracted, as it is disgustingly, obviously, no-way-to-go-wrong, dead easy!
Must be getting too old.. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|