2

I would like to replace the french letter Æ with the asci corresponding AE, but the method does not accept this. Is there another way?

5 Answers 5

10

How about:

myString.Replace("Æ", "AE");
Sign up to request clarification or add additional context in comments.

1 Comment

It should be noted that you make use of double quotes, not single ones. Single ones stand for chars, double ones for strings.
5

Instead of string.Replace('Æ','AE'), use string.Replace("Æ", "AE").

Comments

5

This doesn't work?

string x = "ÆHELLO";
string y = x.Replace("Æ", "AE");

Comments

4

Just call .ToString() on your char:

var str = str.Replace('Æ'.ToString(), "AE");

4 Comments

That seems like a long way around to just putting in: "Æ". Am I missing something?
@Coding Gorilla, yes you're right. It's easier to use a string constant here :)
Ok, I'm one of those dumb US developers that doesn't worry about foreign characters, so I wasn't sure if there was something I didn't know. =)
This actually answers the question.Yes, it is easier to replace a string with another, but the question specified 'String.Replace char to string'. It may well be that the char is a const and cannot simply be changed to a string.
2

This should work since it is a valid Unicode character - are you sure you are re-assigning the string? strings are immutable so this is necessary:

string test = "Æblah";
test = test.Replace("Æ", "AE");//test is now "AEblah"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.