473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

1 liner for String.Split

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?
Nov 21 '08 #1
8 2397
Robert wrote:
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.
Nov 21 '08 #2
"Robert" <no@spam.comwrote in message
news:OD****************@TK2MSFTNGP04.phx.gbl...
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)

Nov 21 '08 #3
>
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, "\")
Nov 21 '08 #4
Robert wrote:
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
Nov 21 '08 #5
>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.
Nov 21 '08 #6
"Robert" <no@spam.comwrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
>>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.

Nov 21 '08 #7
"Family Tree Mike" <Fa************@ThisOldHouse.comschrieb:
>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/>

Nov 21 '08 #8

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message news:eB**************@TK2MSFTNGP04.phx.gbl...
"Family Tree Mike" <Fa************@ThisOldHouse.comschrieb:
>>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..
Nov 22 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
8
by: Paul Watson | last post by:
Can a for loop be used in a one-liner? What am I missing? $ python -c "import sys;print ''.join()," now is the time now is the time $ python -c "import sys;for line in...
0
by: Xah Lee | last post by:
One-Liner Loop in Functional Style Xah Lee, 200510 Today we show a example of a loop done as a one-liner of Functional Programing style. Suppose you have a list of file full paths of...
5
by: g.kanaka.raju | last post by:
main() { printf(&unix, (unix)+"fun"-0x60);} output : unix I have printed &unix ==> output : %six and (unix)+"fun"-0x60 ==> output : un Could anyone of you explain how the above works....
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
12
by: John | last post by:
Hi I have a multi-line address field which has each line separated by CRLF. How can I split this field into individual strings using crlf as separator? Thanks Regards
9
by: jl_post | last post by:
Hi, A few months back I remember reading through C++ newsgroups trying to find a way to quickly convert a number to a C++ std::string. I often see code like: // Create a string that holds a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.