-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.

1 Answers1

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.

Community
  • 1
  • 1
MetaColon
  • 2,895
  • 3
  • 16
  • 38