×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Replace ’ characters from string

Replace ’ characters from string

Replace ’ characters from string

(OP)
I'm reading a CSV file into a c# script and trying to replace certain characters that are causing problems. However, I can't seem to replace ’ which needs to be an apostrophe.

I have tried stripping non-ascii characters with a regex but that leaves a ™ which I then cannot replace either.

Any ideas on how I can replace these unwanted characters?

The source file is being accessed remotely so I have no access to it in terms of changing the encoding

Thanks

Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneysurveys.co.uk
http://www.freemoneyresource.co.uk

RE: Replace ’ characters from string

(OP)
Thanks for reply, this has perhaps got me on the right track.

I can now replace the first two characters using unicode references with a regular expression or simple replace but the TM symbol is still not being replaced.

For example, this does nothing

CODE

new_text = Regex.Replace(new_text, @"\u00E2\u20AC\u2122", string.Empty); 

However, this removes the †characters

CODE

new_text = Regex.Replace(new_text, @"\u00E2\u20AC", string.Empty); 

This leaves the TM character but I need to replace the whole ’ string with a single quote. I do not want to try and replace the TM separately as there will be occasions where there is a valid TM character. Having said that I am having no luck replacing the TM on its own anyway.

I have also tried replacing using other codes for the trademark symbol such as ™ ™ and ™ with no luck.

Any ideas?

Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneyresource.co.uk
http://www.freemoneysurveys.co.uk

RE: Replace ’ characters from string

try looking for "®"

RE: Replace ’ characters from string

(OP)
For those that are interested I have managed to find a workaround solution by using IndexOf to find the position of the first two characters †then using Remove get rid of the those characters and the next one in the string. Then I use an Insert to put the apostrophe in the same place

For example

CODE

while(new_text.IndexOf("\u00E2\u20AC")!=-1) {
		int position = new_text.IndexOf("\u00E2\u20AC");
		new_text = new_text.Remove(new_text.IndexOf("\u00E2\u20AC"), 3);
		new_text = new_text.Insert(position, "''");
	} 

A bit clunky but it works. Would still like to know a solution using replace but this will have to do for now.

Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneyresource.co.uk
http://www.freemoneysurveys.co.uk

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close