Hi,
I am trying a basic opearation of splitting a multiline value to an
array of single lines(Actually making Address into AddressLine1,
AddressLine2).
I used Environment.NewLine in split, I could get only 1st line, but it
is not returning 2nd line.
here's code:
string[] address = null;
string ssep = Environment.NewLine;
char[] sep = ssep.ToCharArray();
address = this.AddressLine1.Split(sep);
this.AddressLine1=address[0].ToString();
this.AddressLine2=address[1].ToString();
Am I doing anything wrong?
Thanks,
Vamsi 5 57131
Vamsi,
NewLine will return the carriage-feed/newline combo. Are you sure that
your lines are delimited with this combo, or is it delimited only by the
newline character?
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Vamsi" <m_*****@hotmail.com> wrote in message
news:3a**************************@posting.google.c om... Hi, I am trying a basic opearation of splitting a multiline value to an array of single lines(Actually making Address into AddressLine1, AddressLine2). I used Environment.NewLine in split, I could get only 1st line, but it is not returning 2nd line. here's code: string[] address = null; string ssep = Environment.NewLine; char[] sep = ssep.ToCharArray(); address = this.AddressLine1.Split(sep); this.AddressLine1=address[0].ToString(); this.AddressLine2=address[1].ToString();
Am I doing anything wrong? Thanks, Vamsi
Vamsi,
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.
Alternatively use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.
If you are using C#, you can reference the Microsoft.VisualBasic.dll
assembly to use the first function.
As Nicholas stated, Environment.NewLine is a string (two characters) you may
want to consider using the VB function or the Regex Method.
Hope this helps
Jay
"Vamsi" <m_*****@hotmail.com> wrote in message
news:3a**************************@posting.google.c om... Hi, I am trying a basic opearation of splitting a multiline value to an array of single lines(Actually making Address into AddressLine1, AddressLine2). I used Environment.NewLine in split, I could get only 1st line, but it is not returning 2nd line. here's code: string[] address = null; string ssep = Environment.NewLine; char[] sep = ssep.ToCharArray(); address = this.AddressLine1.Split(sep); this.AddressLine1=address[0].ToString(); this.AddressLine2=address[1].ToString();
Am I doing anything wrong? Thanks, Vamsi
Your approach seems solid. The following test code works:
string words = "test\n\ntest\ntest\n";
string [] split = words.Split
(Environment.NewLine.ToCharArray());
foreach (string s in split) {
if (s.Trim() != "")
Response.Write("<p>" + s);
}
JER -----Original Message----- Hi, I am trying a basic opearation of splitting a multiline
value to anarray of single lines(Actually making Address into
AddressLine1,AddressLine2). I used Environment.NewLine in split, I could get only
1st line, but itis not returning 2nd line. here's code: string[] address = null; string ssep = Environment.NewLine; char[] sep = ssep.ToCharArray(); address = this.AddressLine1.Split(sep); this.AddressLine1=address[0].ToString(); this.AddressLine2=address[1].ToString();
Am I doing anything wrong? Thanks, Vamsi .
Environment.NewLine ?
Been searching for that for ages.
"Jerry Negrelli" <je************@nospamdatascientific.com> wrote in message
news:04****************************@phx.gbl... Your approach seems solid. The following test code works:
string words = "test\n\ntest\ntest\n";
string [] split = words.Split (Environment.NewLine.ToCharArray());
foreach (string s in split) { if (s.Trim() != "") Response.Write("<p>" + s); }
JER
-----Original Message----- Hi, I am trying a basic opearation of splitting a multiline value to anarray of single lines(Actually making Address into AddressLine1,AddressLine2). I used Environment.NewLine in split, I could get only 1st line, but itis not returning 2nd line. here's code: string[] address = null; string ssep = Environment.NewLine; char[] sep = ssep.ToCharArray(); address = this.AddressLine1.Split(sep); this.AddressLine1=address[0].ToString(); this.AddressLine2=address[1].ToString();
Am I doing anything wrong? Thanks, Vamsi .
We can also do following,
string words = "test\n\ntest\ntest\n";
char[] token = new
char[]{System.Environment.NewLine.ToCharArray()[0]};
string [] split = words.Split(token);
foreach (string s in split) {
Response.Write("<p>" + s.Trim());
}
Regards,
-Maulin
Alvin Pruney wrote: Environment.NewLine ?
Been searching for that for ages.
"Jerry Negrelli" <je************@nospamdatascientific.com> wrote in
message news:04****************************@phx.gbl... Your approach seems solid. The following test code works:
string words = "test\n\ntest\ntest\n";
string [] split = words.Split (Environment.NewLine.ToCharArray());
foreach (string s in split) { if (s.Trim() != "") Response.Write("<p>" + s); }
JER
-----Original Message----- Hi, I am trying a basic opearation of splitting a multiline value to anarray of single lines(Actually making Address into AddressLine1,AddressLine2). I used Environment.NewLine in split, I could get only 1st line, but itis not returning 2nd line. here's code: string[] address = null; string ssep = Environment.NewLine; char[] sep = ssep.ToCharArray(); address = this.AddressLine1.Split(sep); this.AddressLine1=address[0].ToString(); this.AddressLine2=address[1].ToString();
Am I doing anything wrong? Thanks, Vamsi . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kartik |
last post by:
Hi,
I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshell...
|
by: Michael.McD |
last post by:
Would anyone know how I might access to the vbCrLf constant.
I'd like to use teh following bit of VB code in C#:
strFoo.Text.Replace(vbCrLf, chr(10) )
Thanks in advance,
Michael McD
Ps...
|
by: collie |
last post by:
Hi,
I have 2 listboxes. The first gets populated from the db as soon as
the page loads. The second listbox get populated based on the user's
selection from the first listbox. However,...
|
by: Asha |
last post by:
greetings...
i want to split a new line from an input text area and here's what i did
string.Split("\n \r ", ",");
the result, nothing happen...
then i tried this
...
|
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: Gilgamesh |
last post by:
Hi,
I have some very limited knowledge of web development but I have an
imagemap in which I want to be able to display a small yellow circle at
certain pre-define locations. When the user moves...
|
by: Peter Kirk |
last post by:
Hi
I would like to ask a little bit about the value Environment.Newline: what
is it and what is the point of it? Ok, I can see in the docs that it
represents "newline" for the current platform -...
|
by: wisaunders |
last post by:
the file I'm importing has > 200,000 records
I have one problem:
One of the columns in the .txt file (customerID) has almost all Inetger values except for about 30 records. Those 30 records...
|
by: drshah101 |
last post by:
Hi there i have written the following code in C# and was wondering how i can output the script between the <Head></Head> tags i cant use literal as using master page
StringBuilder...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
| |