-3

For example,string A = "your" string B ="YOU"

Result string A = "YOU YOUr".

I have no problem replacing the first word, but for the second word, i cant seem to get the "r" to append to the word.


var description = "you your" STRING[] keywords ={"YOU","a"}

return description.Split().Select(x => keywords.Contains(x) ? x.ToUpper() : x).ToString(" ");

so far, I can get "YOU your", but "YOU YOUr" is what I want.

4
  • 1
    Show what you have tried so far. Demonstrate that you have done your research before asking here. Commented Apr 26, 2017 at 13:31
  • actually ops.. my old attempt didnt work... Commented Apr 26, 2017 at 13:51
  • I am gonna repost this question -5 already in 5 minutes lol Commented Apr 26, 2017 at 13:58
  • I don't even completely understand what the question is here. something that involves using IndexOf and Replace probably fixes whatever you're doing. Commented Apr 26, 2017 at 16:40

1 Answer 1

0

If I undestand you correctly you could simply use string.Replace:

"you your".Replace("you", "YOU");

However, this is case sensitive. If you want to have it case insensitive, you could use regex:

string B = "YOU";
string A = "you your";
var regex = new Regex( B, RegexOptions.IgnoreCase );
var newA = regex.Replace( A, B);

If you want mulitple items to get replaced, simply do this for every replace item.

For more information on Replace, take a look at this: https://msdn.microsoft.com/de-de/library/fk49wtc1(v=vs.110).aspx. The regex idea is from here: How to ignore case in String.replace, you can get more information on Regex.Replace here: https://msdn.microsoft.com/de-de/library/xwewhkd1(v=vs.110).aspx.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.