473,471 Members | 4,687 Online
Bytes | Software Development & Data Engineering Community
Create 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||three";
string[] myStrs = str.Split("||");

This code does not work.

How can I do it?

Yhanks
Hetal
Nov 16 '05 #1
3 19293
Hetal Shah <sh**@jnpr.net> 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||three";
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.Substring.

--
Jon Skeet - <sk***@pobox.com>
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.VisualBasic.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.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

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

Something like:
string str = "one||two||three"; string [] fields = Strings.Split(str, "||", -1,
CompareMethod.Binary);
Hope this helps
Jay
"Hetal Shah" <sh**@jnpr.net> wrote in message
news:uM*************@TK2MSFTNGP11.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||three";
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||three";
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
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(...
3
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
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...
6
by: Webgour | last post by:
How to go from string "abc" to string "a|b|c"?
3
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...
10
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...
35
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#...
7
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...
1
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...
4
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...
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
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.