473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string delimiter

It is a C# code.

I have a string like, one||two||three

I want to split it into one, two and three.
string str = "one||two||thre e";
string[] myStrs = str.Split("||") ;

This code does not work.

How can I do it?

Yhanks
Hetal
Nov 16 '05 #1
3 19304
Hetal Shah <sh**@jnpr.ne t> wrote:
It is a C# code.

I have a string like, one||two||three

I want to split it into one, two and three.
string str = "one||two||thre e";
string[] myStrs = str.Split("||") ;

This code does not work.

How can I do it?


Well, if you use a single character delimiter, eg | instead of ||,
it'll work.

Otherwise, you could use Regex.Split or write your own splitting
routine using String.IndexOf and String.Substrin g.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hetal,
In addition to the other comments.

There are three Split functions in .NET:

Use Microsoft.Visua lBasic.Strings. Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.

Use System.String.S plit if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

Use System.Text.Reg ularExpressions .RegEx.Split to split based
on matching patterns.
By referencing the Microsoft.Visua lBasic assembly in C# you can use the
Strings.Split function to split a string based on a word.

Something like:
string str = "one||two||thre e"; string [] fields = Strings.Split(s tr, "||", -1,
CompareMethod.B inary);
Hope this helps
Jay
"Hetal Shah" <sh**@jnpr.ne t> wrote in message
news:uM******** *****@TK2MSFTNG P11.phx.gbl... It is a C# code.

I have a string like, one||two||three

I want to split it into one, two and three.
string str = "one||two||thre e";
string[] myStrs = str.Split("||") ;

This code does not work.

How can I do it?

Yhanks
Hetal

Nov 16 '05 #3
Hetal Shah wrote:

It is a C# code.

I have a string like, one||two||three

I want to split it into one, two and three.

string str = "one||two||thre e";
string[] myStrs = str.Split("||") ;

This code does not work.

How can I do it?

Yhanks
Hetal


Could you do something like this:

string [] myStrs = str.Replace("|| ", "|").Split( new char[]{'|');
Nov 16 '05 #4

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

Similar topics

5
1788
by: Christopher Benson-Manica | last post by:
The function in question follows: vector<string>& tokenize( const string& s, vector<string>& v, char delimiter=',' ) { int delim_idx, begin_idx=0, len=s.length(); for( delim_idx=s.find_first_of(delimiter,begin_idx) ;
3
2461
by: Old Wolf | last post by:
Hi all. G++ fails to compile the following: #include <string> int main() { std::string foo("abc=123"); std::string::const_iterator delimiter = std::find(foo.begin(), foo.end(), '=');
5
18930
by: Adam Parkin | last post by:
Hello all, I am seeking some help with the following problem. I'm working on an application where I have a resource file, and in this resource file what I want to store is a list of file names (that is, essentially a string array). The potential solutions I see are: 1) Convert the string array into one big string with each element...
6
2183
by: Webgour | last post by:
How to go from string "abc" to string "a|b|c"?
3
6022
by: Rico | last post by:
If there are consecutive occurrences of characters from the given delimiter, String.Split() and Regex.Split() produce an empty string as the token that's between such consecutive occurrences. It sounds like making sense, but has anyone ever found this useful? Can this 'feature' be disabled? After having used StringTokenizer from the...
10
2861
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could someone let me know if the method I've used below is efficient or if there is a better way to do it, as these will be rather large strings I'm...
35
2531
by: Cor | last post by:
Hallo, I have promised Jay B yesterday to do some tests. The subject was a string evaluation that Jon had send in. Jay B was in doubt what was better because there was a discussion in the C# newsgroup on 25 September. The regular expressions where in that newsgroup too involved. I told yesterday night, to Jay that I would test all 4...
7
8561
by: Felix85 | last post by:
I am trying to make a command interpreter for a mud that i am working on the problem i am having right now is that i cannot convert the string into a char array. This is the error I am getting now: In file included from src/mud.cpp:3: src/command.h: In static member function `static void command::getCommand(std::string)':...
1
3042
by: kellysgirl | last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written. The instructions I was given are as follows In this case, you will create a Visual Basic 2005 solution that manipulates strings. It will parse a string containing a list of items within a text box and put the individual...
4
3405
by: kretik | last post by:
I've been trying to coax this class to use something other than the default '$' but it seems setting it to something else has no discernible effect. Is it necessary to inherit from the class to do this? I've only been using Python for a couple of weeks so I'm not sure what the best approach is here. Thanks in advance.
0
7457
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7391
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7410
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7746
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.