Why String.Split(char[]) is possible but String.Split(string[]) is Not!

Hi everyone,

i have a string for e:g

String st= "Delete a record****** *************************************************** Delete Manually PatID=123456 PatName=navdeep *****Delete a record****** *************************************************** Delete Manually *****************PatID=123 PatName=navdeep6666"

I need to Split this String by "Delete a record" string. Now, str[] will contain the array elements. str = st.Split("Delete a record");

Please Help

Regards

Navdeep

0
navdeepkooner
6/10/2008 10:11:45 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

6 Replies
1197 Views

Similar Articles

[PageSpeed] 16

check below link or try code 

 http://www.codeproject.com/KB/dotnet/TextQualifyingSplit.aspx

 

 

public string ConvertHTML(string RawHTML)
{

string[] SplitHTML;
Sytem.Text.StringBuilder FinalHTML = new Sytem.Text.StringBuilder();

SplitHTML = RawHTML.Split("<td>");

for (int i = 0; i <= SplitHTML.Length - 1; i++)
{
FinalHTML.Append(RawHTML(i));
if (i == 3 || i == 5 || i == 8)
{
FinalHTML.Append("<td class=\"SpecialFormat\">");
}
else
{
FinalHTML.Append("<td>");
}
}

return FinalHTML.ToString();
}


View Blog

linkedin Asp.net Group

Don't forget to click “Mark as Answer” on the post that helped you
0
sameer_khanjit
6/10/2008 10:34:22 AM

Hi,

    If I've understood correctly then you want something like:

<code>

string[] str = st.Split(new string[] { "Delete a record" }, StringSplitOptions.None);

</code>

HTH

0
clarky
6/10/2008 10:42:00 AM

Hi Sameer

 

In the Code :

RawHtml.Split(Char[]);

The Split function accepts only Characters. If i want that it should accept string then what approach i should follow?please clarify

Secondly, If i want to  have Deliminators on the String , then how can i do it with the help of StartsWith and EndsWith methods?

 

Thanks In Advance

Regards

Navdeep 

0
navdeepkooner
6/10/2008 12:02:36 PM

first of all Please view this following link :-

 http://msdn.microsoft.com/en-us/library/tabh47cf.aspx

and try this below code Using Substring....

str1=Str.Substring(Str,0,Str.indexOf("Delete"));

str2= Str.Substring(Str,Str.indexOf("Delete"),Str.Length);

Str= str1+str2;

 



View Blog

linkedin Asp.net Group

Don't forget to click “Mark as Answer” on the post that helped you
0
sameer_khanjit
6/10/2008 12:09:47 PM

Hi,

 

You can do this by follwing code:-

string s = "Delete a record****** *************************************************** Delete Manually PatID=123456 PatName=navdeep *****Delete a record****** *************************************************** Delete Manually *****************PatID=123 PatName=navdeep6666";

string[] s2 = s.Split(new string[] { "Delete a record" } , StringSplitOptions.None);

for (int i=0;i<s2.Length;i++)

Response.Write(s2[i].ToString() );

Thanks.

 

0
Tulika
6/10/2008 12:26:37 PM

Hi Sameer

 

Its  working fine

 

Thanks a lot

Regards

Navdeep 

0
navdeepkooner
6/11/2008 6:15:54 AM
Reply:

Similar Artilces:

how to split a string by a string not a char?
I've used the split('?') function on strings to good effect to delimit them up based on a single char but I'm looking through the overloads and can't see one for how to split a string by a string pattern. My source string is called Session["basket"] and is in the format A/B and I want to change it also include C, however A/B/C and split by '/' won't be 100% reliable because C is actually gotten from user input so they could input forwardslashes and thus mess things up, so a possible solution may be to do something like A#@#B#@#C and then do a Session...

split string by string
Hi All I am trying to split a string with other string. Does any one help me how to do this.I have "237943--;--dgsa78a--;--dasd732" I want to split with --;-- And ideas please thanks,Aruna.G     string contents = "237943--;--dgsa78a--;--dasd732"; you can do contents.split(';')which would split it on ; Thanks,Karan~ Remember To Mark The Post(s) That Helped You As The ANSWER ~ You can use String.Split(String[], StringSplitOptions)   string source = "237943--;--dgsa78a--;--dasd732"; string[] ...

Splitting a String into Usable strings
How do I split up a string that has data that is separated by a comma?  I used the SPLIT method, but the method put the data into an array.  The array will not allow me to send the data into a string to be used.    What can I do??? What do you want to achieve by splitting the string? An array will let you access each segment individually. string numbers = "1,2,3,4"; string[] s = numbers.Split(",".ToCharArray()); string firstNumber = s[0]; In case you want to bring the splitted string back to a flat string you should take a look at the String.J...

string to string[]
Hi, I've got this code : string[] Params; string SQL = "SELECT * FROM T_MANAGEMENT_PAGES"; SqlCommand myCommand = new SqlCommand(SQL, myConnection); myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { Params_Type = myReader.GetValue(0).ToString(); } } catch { } finally { } myReader.Close(); My problem is to obtain Params_Type. But each time, it says : "impossible to convert '[object]' in 'string[]' &quo...

string and string[]
hello, whats the difference here between string and string[] thanks "string" denotes an item of type String "string[]" denotes an array of type String itemsThanks, EdMicrosoft MVP - ASP/ASP.NET Gracia mon ami...

String and String[]
What will be the advantage of using myString: String[10] over myString: String Man wrote: > What will be the advantage of using > myString: String[10] > over > myString: String "String[10]" is a fixed-length, statically allocated, Ansi-based ShortString. "String" is a dynamic-length, dynamically allocated, reference counted, Ansi-based or Unicode-based (depening on Delphi version) Long string. Unless you absolutely need the static, fixed length nature of ShortString, such as in records that interact with external systems, you should stay ...

String and string?
Hi guys, I was wondering the difference between small letter string type and a capital letter String type. Does anyone know about this? Highly appreciate for your answers! Thankz! The "proper" version is String, as it references the System.String class of the .NET Framework Class Library. The ability to use string is provided by C#, where it is an alias to String. Similarly, the "proper" version of an integer is Int32, as it references System.Int32.  The ability to use int is provided by C#, and the ability to use Integer is provided by VB.NET, and both int and Integer are aliases...

string() = string()
this code does not work (not instance of object) Dim Items(), Other() As String Items = New String() {"A","B","C"} Other = New String() {} Other = Items how can I get all the values ? angiras Hi, If I understand your requirement correctly, this should do it Dim Items() As String = {"A", "B", "C"} Dim Other(Items.Length - 1) As String Items.CopyTo(Other, 0) To more closely match you code above, but this will be less efficient Dim Items(), Other() As String ...

splitting a string of alphanumeric into two string
Hi, Just a question on what the easiest way is to split a string that starts w/ alphabetical characters and ends w/ numeric numbers into two.  i.e. String: JonPT233 Split the above into two string:  1st string:  JonPT 2nd string:  233 I was looking at the Split() function but it doesn't have a direct way of splitting aphanumeric characters into what I want...so is going through character one by one and creating two separate arrays checking if it's alphabetical or numeric the only way or is there an easier, more direct way of doing this?  thanks. The ...

String.Split a StreamReader.ReadLine() string
Hello one and all, I'm developing a system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split() the string returned by readline() on the file. The following code snippet works for me: tokens = "one,two,three,four".Split(",") for each token in tokens response.write("<td>"+token+"</td>") next However, if I take the next line in the CSV, read using StreamReader.ReadLine on the PostedFile.InputStream, I receive "Object refer...

a string in a string in a string in my code behind....
I know my title talk about code-behind, but this is really a client-side problem (and surely a newby one too, sorry about that).I have a javascript function that my make a little text appear when the onmouseover event of a link is activated.So, normally, if my link was inside my html code, it would be something like this:<a href = "whocare.com"  onmouseover="poplink('I want to test something');">test</a>BUT, for some reason, I have to write this part in code behind with the LiteralControl function....and that will give something like that:this.Controls.Add(new LiteralCo...

splitting a string of characters and numbers into separate strings
Hi,  I was looking at the Split() function in vb.net but don't know if there's an easier way to do this.  I have a string that is alphanumeric.  It starts with alphabetical characters and ends with integers.  The length varies from one record to another.  I had to concatenate the two to have them appear together in a dropdown list.  However, when a user selects it, I need to split it in two different strings, one that holds just the alphabetical characters and one that has just the integer values.  Is there an easier way than just going through the...

Splitting string using split()
Gurus: I have a string like this: $s = 'jablow@xxx.com, "Blow, Joe" <jablow@xxx.com>,Joe Blow <jablow@xxx.com>' And I want to be able to split it up. Using split, like this: my @addresses = split(/, ?/, $s); But obviously this causes a problem because of the comma inside the quotes. I want three parts, and it splits it into four. Is there some module or nice way to have the commas inside quotes ignored? Reply to perlbeginner@mikemiller.net if possible as I'm only getting the daily digest of this list. Thanks, -Mike This seems ...

m_AVP As IDictionary(Of String, String) = New Dictionary(Of String, String) ,not defined?
   I am creating a usercontrol (ascx,ascx.vb)   I have used Imports system.Collections Imports system.Collections.Generic     Private m_AttributeValuePair As IDictionary(Of String, String) = New Dictionary(Of String, String)     But I am gettting an error “Type Dictionary is not defined”   And also I am getting intelisense to type the line But what is the reason for my error ? How can I get escape from the error ?         this error is not showing today  ...

Web resources about - Why String.Split(char[]) is possible but String.Split(string[]) is Not! - asp.net.getting-started

Resources last updated: 11/28/2015 6:45:56 PM