473,326 Members | 2,126 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,326 software developers and data experts.

C#-APP: Splitting a string by a character

Hello, I have a quick question:

I have a string in the following format:

|001|ACOMMAND|argument1|argument2|

Now I need to get 'argument1' and 'argument2'. For the other strings I used StringBuilder.Remove, since they both have a fixed lengths. But 'argument1' and 'argument2' dont have a fixed length, so I cant use that.

Is there a function that lets me split the string by the '|'?

Thanks in advance!
Nov 29 '07 #1
1 918
Plater
7,872 Expert 4TB
There is indeed a string split() function.

Consider:
Expand|Select|Wrap|Line Numbers
  1. string mys="001|something| something else| super duper!| last one";
  2. string[] allpieces=mysSplit('|');//note that I used single quotes there to designate a character
  3. //now allpieces will be like this:
  4. //allpieces[0]= 001
  5. //allpieces[1]= something
  6. //allpieces[2]=  something else
  7. //allpieces[3]=  super duper!
  8. //allpieces[4]=  last one
  9.  
Also, there is a .IndexOf() function that will tell you the position of a character in a string ( -1 if it doesn't exist in the string) and then you could use .Substring() to pick which pieces you want.
Nov 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: David Pratt | last post by:
I have string text with language text records that looks like this: 'en' | 'the brown cow' | 'fr' | 'la vache brun' Two or more language records can exist in each string (example above shows 2...
0
by: lungwahchong | last post by:
Hi, I have these strings which are pulled from a database which contains both english and chinese characters(big5). e.g. Fragrant Rice 10kg Green Dragon???? Broken Rice 10kg G.Elephant...
1
by: Mike | last post by:
Help, I am using an encryption routine that occasionally will encrypt a string using some extended ASCII characters (ASCII code > 128) I am wondering if there is a reserved character in VB that...
1
by: Guadala Harry | last post by:
I have a string that must be split out into a string array. The segment delimiter is like this: {flag:xxx} and the "xxx" part is unknown ahead of time (can be just about any character AND any...
1
by: sadiewms | last post by:
Hello! I have a flat file that I'm trying to get into a relational Access 2003 DB. One of the fields in the flat file has a list of names separated by ";". I'd like to loop through them and...
7
by: Anat | last post by:
Hi, What regex do I need to split a string, using javascript's split method, into words-array? Splitting accroding to whitespaces only is not enough, I need to split according to whitespace,...
4
by: VMI | last post by:
How can I split a string that looks like this: John, Doe, 37282, box 2, 10001, "My description, very important", X, Home If I use String.Split(), it'll split the string that's between the...
3
by: Ramper | last post by:
I need to Write a function that will, given an input string containing many words, split that string into individual words. For each word, the function should output the word, its starting index in...
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
10
by: CSharper | last post by:
I have a html page that I retrived and stored in a string and I want to split it based on <tdelements. I know only way you can split using string.split is using characters. The other option is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.