.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

Remove characters in a string

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

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....

View Complete Post

More Related Resource Links

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

string.Split - not all characters allowed as separator



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.



Remove japnese / russian words in a String

Hi, I"m currently writing a ASP.NET MVC application in which I search twitter for new tweets. When however I use the language filter I still get some messages in japanese or russian. I tried using a Regular expression: [^\x20-\x7E\wáéíóäëiöúàêèììçù… ] which should tell me when a string contains japanese/NON ASCII characters. At least that's the output I get when I try checking this regex with a JavaScript function. This is my code: ----------- Regex languagesReg = new Regex(@"[^\x20-\x7E\wáéíóäëiöúàêèììçù… ]"); lstEntries.RemoveAll(e => languagesReg.IsMatch(e.Content)); -----------           Does anyone know why I get the right output with JavaScript functions and the wrong output in .NET? Or maybe someone might be able to help me find an other workaround? Thanks in advance Kasper

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?

remove pattern from string as seperate column

Hey  Everyone This seems like it shouldn't be too difficult but I'm strapped for time- I have a column where the data looks like CN=kmcde,OU=People,DC=ad,DC=FLA,DC=edu I want to pull out the 'kmcde' as a new column. I'm thinking some combination of substring and perhaps patindex but can't get it to work correctly Thanks kam

Best Method to remove special character from string

I am trying to remove the special characters from a string that was entered by the user.  I am not sure the best method to do this.  i can get a foreach of all the characters but what do i check it against?
Christian - developer

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?





How to remove all xmlIns from this xml string



I have a string which is XML. I have to remove all the XML namespaces from this string. That is creating lots of problems while updating XML element values.

Here is my XML. Now out of this XML, I want to remove all the xmlIns, xmlIns:xsi and xmlIns:xsd, I mean all the XML Namespaces.

Can someone provide C# code to do this please?


<?xml version="1.0" encoding="utf-16"?>
<ServerInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <GenerationDate xmlns="http://www.MYSITE.com/WebServices">10/5/2010 12:53:13 PM</GenerationDate>
  <Customer xmlns="http://www.MYSITE.com/WebServices">
    <ContactAddress>200 Cottontail Ln
Somerset, NJ 08873</ContactAddress>
    <Notes />
    <Organization>Ventiv Health</Organization>
  <LAServerHistory xmlns="http://www.MYSITE.com/WebServices">
    <Notes>9/2/09 SO 41233
9/8/09 SO 41369
9/25/09 TL loaner
7/23/10 FR/Convert to perm</Notes>

Remove tab from the string



How to remove tab from the string?

Remove foreign characters from data


I have date in my results where squares appear - how to i replace non-letter characters with empty string...They are squares in windows they are like ALT + 0 + 1
+ 1+1

I have tried trim , rtrim - no luck


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?

Cleaning a string input from bad characters


Can anyone advice of the best way to clean an input string from characters that will cause SQL Update error? For instance:

Dim sText as string = 'this is line to a break <br>  before the end.'
Dim SQLString as string = "update sometable set somefield='" & sText & "'"

Executing SQLString will fail because of the <br> it contains. Any idea how to filter out all possible characters that will cause the update query to fail?

how to remove "�" from a string c#



how can i remove "&#x0;"  from a string c#


thanks in advance

remove unwanted parts of a string of html tags


hi,all, I have a string of tags like:

<A href

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Connestion string create any database server

This links important to how to create connection string to any data base sever.
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