Click here to Skip to main content
15,795,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a StringBuilder SB where i append unicode words from a textarea. Where ever "െ" or "േ" or "്ര" comes it has to be moved one position to the right using C#.

Example if i have െത any where in the stringbuilder it has to be replaced as തെ we dont have an idea of what will come after െ
How can I do this?

Updated 24-Oct-10 5:10am
Abhinav S 24-Oct-10 11:55am    
In addition to the answers below , you might want to try regex patterns here.

Convert it to a string, then do something like this:
var result = Regex.Replace("abcdedcba", "c.", new MatchEvaluator(delegate(Match m) {
    return m.Value.Substring(1, 1) + m.Value.Substring(0, 1);

That assumes the lowercase character "c" is what will be moved one character to the right (except in the case that it is already the last character in the string, in which case it will be left alone).

You may want to use the Regex constructor so you can pass options, such as ignoring case or specifying how to handle newline characters. Regular expression are pretty flexible, so you could also do something like this too:
var result = Regex.Replace("abcdedcba", "(?<FIRST>c)(?<SECOND>.)", "${SECOND}${FIRST}");

You'd have to modify it if you want to account for groups of characters you want to move to the right by one.

EDIT: To account for the scenario you mentioned in a comment to this answer, you might try something like this:
var val = "F073 F058 F06D F073 F020 F068 F053 F0A1 F06D F02D F074 F073 F0A9";
var result = Regex.Replace(val, "(?<FIRST>F073) (?<SECOND>....)", "${SECOND} ${FIRST}");
Share this answer
rowdykuttan 24-Oct-10 14:06pm    
Yes this is great but my string is little bit different.

I have a string with values F073 F058 F06D F073 F020 F068 F053 F0A1 F06D F02D F074 F073 F0A9

Now i want to swap the words where ever there is F073 the next word should come first then F073. in the string you will find 3 occurrences of F073 so this has to be replaced like F058 F073 F06D F020 F073 F068 F053 F0A1 F06D F02D F074 F0A9 F073
Use regular expressions[^].

Share this answer
You can try this..

// Correct the spelling of "document".
string correctString = errString.Replace("docment", "document");
Share this answer
rowdykuttan 24-Oct-10 10:20am    
This is not a document i am trying to replace on the RUN

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900