469,326 Members | 1,359 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

How to add text before a specific character

7 Nibble
In my project I want to add text before the character I will choose. Could you explain how I can do it?
4 Weeks Ago #1

✓ answered by cactusdata

Use Replace method:

Expand|Select|Wrap|Line Numbers
  1. string input = "This is my sentence.";
  2. string specificCharacter = "e";
  3. string prefix = "x";
  4. string result = input.Replace(specificCharacter, prefix + specificCharacter);
  5.  
  6. Console.WriteLine(input);
  7. Console.WriteLine(result);
  8.  
  9. // Output.
  10. // This is my sentence.
  11. // This is my sxentxencxe.

3 3256
dev7060
504 Expert 256MB
In my project I want to add text before the character I will choose. Could you explain how I can do it?
Elaborate the question (since this has been posted under general).
4 Weeks Ago #2
cactusdata
177 Expert 128KB
Use Replace method:

Expand|Select|Wrap|Line Numbers
  1. string input = "This is my sentence.";
  2. string specificCharacter = "e";
  3. string prefix = "x";
  4. string result = input.Replace(specificCharacter, prefix + specificCharacter);
  5.  
  6. Console.WriteLine(input);
  7. Console.WriteLine(result);
  8.  
  9. // Output.
  10. // This is my sentence.
  11. // This is my sxentxencxe.
4 Weeks Ago #3
Jordan Cooper
7 Nibble
Thank you, it really helped!
4 Weeks Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Fuzzyman | last post: by
1 post views Thread by Hyrum Mortensen | last post: by
9 posts views Thread by Martin Nadoll | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.