.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

string.Split - not all characters allowed as separator

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net


I am working on a site where I use the Split function on a string.

To make sure I used a separator character that I do not use anywhere in the data I selected the character '£'.

This worked fine in Firefox and Safari, but in IE8 I get an 'Index out of range' error, so apparently the '£' character is not handled correctly.

I changed the separator to ';', and then it works fine.



View Complete Post

More Related Resource Links

String.Split with with tab as separator


I should read the substrings of this file:

1	1	-1738.20118241	6787.03549108	
2	2	-1803.20118241	6759.73549108	
3	3	-2193.20118241	6759.73549108	

I haved used the tab control "\t" as the separator (there is a tab character between the columns):

      Dim separator() As String = {"\t"}
      Console.WriteLine("separator(0) = {0}", separator(0))
        ' Open the file to read from.
        Using sr As StreamReader = File.OpenText(nomeFile)
          Do While sr.Peek() >= 0
            'Dim line As New StringBuilder
            Dim stringline As String
            Dim stringarray As String()
            Dim x, y, canale 

Problem Cleaning Illegal Characters out of an XML String



I'm trying to strip illegal characters out of an XML string before I send it off to a public web service.  The xml will look something like this:

<field name="first_name">George</field>
<field name="last_name">Harrison</field>
<field name="notes">This is a note.  Any character could appear here</field>

I need to pull out any ampercand (&) charachters in the any of the fields, as well as any < or > characters, which would make the XML unreadable.

I've tried it like this:

Private Shared Function cleanQuery(ByVal queryNode As String) As String 
    Dim root As XElement = XElement.Parse(queryNode) 
    For Each x As XElement In root.Elements 
        x.Value = x.Value.Replace("&", "&").Replace("<", "<").Replace(">", ">") 
    Return root.ToString() 
End Function


That doesn't work so well.  I get the error stating:

     There are multiple root elements. Line 1, position 15.

I tried wrapping the XML in a single root element, like this:

Private Shared Function cleanQuery2(ByVal q

Remove characters in a string


i have a string like this   sravani/, asdfff/, lsdsf/
i want to remove last character '/'  in the above string...
which function can i use?

pls help me....

How to split string?


I have a string that looks like this: pic1*pic2*pic3*

I want to take out every pic from the string like this:


I got the first pic but how do i get the other two?

Dim line as string = "pic1*pic2*pic3*"
Dim pic1 As String
Dim pic2 As String
Dim pic3 As String

pic1 = line.Substring(0, line.IndexOf("*"))
pic2 = ?
pic3 = ?

Split string using Regex with escape sequences

What is the regex to split a string using the delimiter ';', but not split on '\;' ? Backslash would be my escape character in my split string, so finding '\;' would not split, but '\\;' would split. For example I want a regex that would split the following:     "aaa;bb;cccc\;dd\;eee\\;ff\\;ggg\\\;hhh" into the following string array:     aaa     bb     ccc\;dd\;eee\\     ff\\     ggg\\\;hhh   Thanks!   -Sylvain

How to split the string value ?

 Hi I  have a string value ie) = '1001010' I want to split one word by one word. like  as 1 0 0 1 0 please guide me.  

Filtering Special Characters Quickly From A String

I need to only allow (basically every key that you can see on the keyboard) and drop the rest. I would probably use a regular expression to do this but Im not that great with them at this time. Does anyone have an example of how to do this?

Split a String from a listbox to enter data in a table


Currently, I have a listbox that the selected items are inserted into the database by a string. Now I need to add a new feature that the searches are suppose to be postback individually so the selected values from the listbox need to be inserted into the database individually so the search can work. Is it possible to split an string into separate variables or into an array?

Thanks for your help,



Following is my store procedure and my back code:

<script runat="server">
    Protected Sub insertcompanydata_click1(ByVal sender As Object, ByVal e As EventArgs)

        Dim tobresults2 As String        
        Dim li As ListItem
        Dim myArrayList As ArrayList = New ArrayList()
        Dim strarr() As String
        For Each li In txttoblb.Items
            If li.Selected = True Then
            End If

        strarr = myArrayList.ToArray(Type.GetType("System.String"))
        tobresults2 = String.Join(",  ", strarr)

        Dim txtloblb1 As String
        Dim lin As ListItem
        Dim myArrayList1 As ArrayList = New ArrayList()
        Dim strarr1() As String

How to count characters in a string, by type


Say I have a string in a text box like


I wish to count the number of pipes or '|'.

How can I do this with js ???

Problem extracting the middle characters of a text string


I need to extract a portion of text from one field and put it in another field and I am having trouble with the syntex.  I am doing this with an sql select statement in asp.net. 

I can select the left most characters of the field (SELECT  BatchNumber, LEFT(BatchNumber, 3) AS Expr1 FROM  DonorHistory) or the right most characters of the field (SELECT BatchNumber, RIGHT(BatchNumber, 3) AS Expr1 FROM DonorHistory) but I cannot select characters from the middle of the field.  I expected that to be able to use a statements such as "SELECT BatchNumber, mid(BatchNumber, 3, 2) AS Expr1 FROM DonorHistory" but this statement gives me an error.  I also tried using middle in place of mid but that did not work either.

What am I doing wrong?





Error: The variable System::ErrorDescription contains a string that exceeds the maximum allowed leng


i get the following error message, when I try to email the error description, by invoking a 'Send Mail Task' in OnError event.

"Error: The variable System::ErrorDescription contains a string that exceeds the maximum allowed length of 4000 characters."

Any idea how to resolve this issue? I am using substring when I build the expression. But still am facing this issue.

Split string


hi all

i want to spilt 115:USD:LKR this string from oracle script. return value should be 115.

pls provide me sql script


Split string after word


Hi everybody,

How can I split a string from some word.

string test = "Hellow world one two three";

I would lile to get the string part after the word world?? The result will be after splitting the string: "one two three"

split string sql server 2005



I have a table called SubjectRank that provides subject and it's ranking.

I have a string that can be in any format. It can be 'hello cat, how -are you lion?' or 'yes horse'. In short it can be received in any manner and i have no control on how user sends the string.

What I need to do is check if the string contains any words in the subject column. If yes I need to return that word.

In addition if the string contains more than one subject from the table than I must check the ranking and return the value with the highest ranking. (1 lowest) So if the string contains 'hello cat, how -are you lion?' the sp must return the word lion.


How can I achieve this?




Multiline Text allowed characters or tags


So before I write a custom field to replace the use of the OOTB multiline text field could anyone tell me a couple things?

First, could someone better explain the reason that script and iframe tags were allowed in content editor web parts but not in the multiline text RTE?

Second, is there a way to enable the use of unsafe tags within the multiline text field without having to create a custom field?


String Builder returning some extra characters



I've built a workflow item to set a variable to a combination of multiple fields through String Builder.

It seems to be adding a characters like  ;  and #  (see below) when the results are fed into a field.

Example:   20 Metronix ;#Dimensions Incorrect;#
It should read  20 Metronix Dimensions Incorrect
Any ideas on why this would occur?

Split String on underscore



I have a long string and i want to split it on the bases of case change and underscore. here is the following pattern that split on the case change but i also want to split it on the underscore. Can somebody help me out.

private static final String DIVIDER_PATTERN =  "(?<=[^\\p{Upper}])(?=\\p{Upper})"  + "|(?<=[\\p{Lower}])(?=\\d)";

 this pattern split "MyFamilyNameIsFar" to "My Family Name Is Far" but i also want to split if there is underscore. like

"MyFamily_NameIs_Far" to  "My Family Name Is Far"

Can somebody tell me which modification i need in this pattern to handle these kind of situation.


your help would be appreciated.


With Best Regards

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend