-3

I'm trying to find out if a String contains another string like this:

var s1 = "Test name*"
var s2 = "TestName"

If checked now it should return true.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
  • 8
    `s1` does not contain `s2` and `s2` does not contain `s1` in your example, so it is unclear exactly what you are wanting from this. – crashmstr Aug 21 '17 at 14:25
  • Wait what? This should return true? It's either duplicate or unclear or broken! Feel free to Use the mighty [Edit] Button! – Drag and Drop Aug 21 '17 at 14:27
  • This search with current value of s1 and s2 will return false. – Amit Kumar Singh Aug 21 '17 at 14:28
  • It's a duplicate question. – Amit Kumar Singh Aug 21 '17 at 14:37
  • Are you trying to check that if both strings have whitespace removed and you are not worried about capitalization that one could be contained in the other? – Kevin Cook Aug 21 '17 at 14:40
  • Basically, If 2 string Are obviously different with ahve to do classical string operation to check if different this way `"Tom Marvolo Riddle"` and `"I am Lord Voldemort"` return true. – Drag and Drop Aug 21 '17 at 14:54
  • It could be cool if the Function have a Culture invariant so `"Tom Servolo Riddle"`and `"I am Lord Voldemort"` return true too as It's the Spannish version of `"Eis Lord Voldemort"` – Drag and Drop Aug 21 '17 at 14:58

1 Answers1

0

Try this:

var exists = s1.Replace(" ", "").Tolower().Contains(s2.ToLower());
esnezz
  • 619
  • 1
  • 7
  • 19