string sTest="TEST1||TEST2";
string[] asTest =Regex.Split(sTest, "||" );
I want to get an array with two elements TEST1 and TEST2, but it returs
every char inside the sTest as a seperate array element.
Thanks,
Jianwei 5 1414
Why not just:
string[] asTest =sTest.Split("||".ToCharArray());
--
Adam Clauss ca*****@tamu.edu
"Jianwei Sun" <js***********@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... string sTest="TEST1||TEST2"; string[] asTest =Regex.Split(sTest, "||" );
I want to get an array with two elements TEST1 and TEST2, but it returs every char inside the sTest as a seperate array element.
Thanks, Jianwei
This will return an array with three elements with one empty string
inside, instead of two. Still, appreciate your reply.
Adam Clauss wrote: Why not just: string[] asTest =sTest.Split("||".ToCharArray());
Try escaping the pipes.
string sTest = "TEST1||TEST2";
string[] asTest = Regex.Split(sTest, @"\|\|");
--
Tim Wilson
..Net Compact Framework MVP
"Jianwei Sun" <js***********@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... string sTest="TEST1||TEST2"; string[] asTest =Regex.Split(sTest, "||" );
I want to get an array with two elements TEST1 and TEST2, but it returs every char inside the sTest as a seperate array element.
Thanks, Jianwei
Work beautifully, thanks.
John
Tim Wilson wrote: Try escaping the pipes.
string sTest = "TEST1||TEST2"; string[] asTest = Regex.Split(sTest, @"\|\|");
Ahhh.... you're absolutely right - sorry!
--
Adam Clauss ca*****@tamu.edu
"Jianwei Sun" <js***********@gmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl... This will return an array with three elements with one empty string inside, instead of two. Still, appreciate your reply. Adam Clauss wrote: Why not just: string[] asTest =sTest.Split("||".ToCharArray()); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: H |
last post by:
This is kind of an followup on oneof my previous questions, and it has with
RegEx to do.
I have a string containing of several words. What would a good regex
expression looklike to get one match...
|
by: dchan1 |
last post by:
String line = " I am new to c# ";
How to use Regex to split the string so that It would return a String array
with:
token = "I"
token = "am"
token = "new"
token =...
|
by: Ali-R |
last post by:
Hi all,
I am getting a CSV file like this from our client:
"C1","2","12344","Mr","John","Chan","05/07/1976".........
I need to validate **each filed value** against a set of rules ,for...
|
by: Cor |
last post by:
Hi Newsgroup,
I have given an answer in this newsgroup about a "Replace".
There came an answer on that I did not understand, so I have done some
tests.
I got the idea that someone said,...
|
by: Michael D Murphy |
last post by:
Hi,
I would like to know how to use Regular Expressions to iteratively return
and print the items between the colons in the following string to say the
console..
Any help would be appreciated....
|
by: yxq |
last post by:
Imports System.Text.RegularExpressions
Dim objRegex As Regex
MessageBox.Show(objRegex.Split("C:\Test.txt", ":\")(0))
The error will occour, seem that the "\" can not become list separator.
If...
|
by: Jordi Rico |
last post by:
Hi,
I know I can split a string into an array doing this:
Dim s As String()=Regex.Split("One-Two-Three","-")
So I would have:
s(0)="One"
s(1)="Two"
|
by: adamisko |
last post by:
Hello, what is wrong with this code, I want to divide string to pieces 4
chars length.
string tekst = "divide string to 4 chars pieces";
Regex regex = new Regex("(.{1,4})");
string substrings =...
|
by: Stevo |
last post by:
If you split a string into an array using the split method, it's not
working the way I'd expect it to. That doesn't mean it's wrong of
course, but would anyone else agree it's working somewhat...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |