-5

I have this sentence <>><<>, I want to remove <> character from that sentence.

example:

<>><<>

should become:

><

All <> should be removed from the sentence.

I dont know what should i use.

stuartd
  • 66,195
  • 14
  • 128
  • 158
Hossein
  • 23
  • 5
  • 4
    `string.Replace("<>", string.Empty)` – MindSwipe Aug 05 '20 at 11:43
  • 4
    what does this have to with python? Asside that what did you try? If you search for "replace string by another in c#" or "remove substring in c#" you´ll probably foijd your answer yourself. – MakePeaceGreatAgain Aug 05 '20 at 11:43
  • 2
    Does this answer your question? [How to remove a defined part of a string?](https://stackoverflow.com/questions/5312211/how-to-remove-a-defined-part-of-a-string) – xdtTransform Aug 05 '20 at 11:53
  • Does this answer your question? [Replace Line Breaks in a String C#](https://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c-sharp) – Cleptus Aug 05 '20 at 12:02
  • @xdtTransform That one point to string.Substring instead of string.Replace – Cleptus Aug 05 '20 at 12:04
  • Does this answer your question? [How to replace all occurrences of a string?](https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string) – izlin Aug 05 '20 at 14:12
  • @MindSwipe thanks for youre answer, if it was many sentecese like ><><><><><<><><><>><_>>>><<>, how should i calcute them in C# – Hossein Aug 05 '20 at 14:20
  • @HimBromBeere could you coding that I don't know what should I use for that? – Hossein Aug 05 '20 at 14:22
  • @xdtTransform i dont think so i dont know if there is the many sentences for that what should i do example=<><><><><<<<>><>,><><<<<< what should i do now? – Hossein Aug 05 '20 at 14:25
  • Does this answer your question? [C# string replace](https://stackoverflow.com/questions/16839401/c-sharp-string-replace) – YLJ Aug 05 '20 at 14:58

1 Answers1

-1

Since you're answer is posted with python tag I'll reply with both languages.

Python:

string = '<>><<>'
print(string.replace('<>', ''))

C#: You can follow 2 ways:

  1. Specify in an Array the characters you want to delete (in case you want to delete multiple characters)

  2. Delete directly the characters

1:

var str = "<>><<>";
var charsToRemove = new string[] { "<>", "another character you want to remove"};
foreach (var c in charsToRemove)
{
    str = str.Replace(c, string.Empty);
}

2:

string = "<>><<>"
string.Replace("<>", string.Empty)
Silvano H.
  • 13
  • 4
  • plus, you should search on StackOverFlow before starting a new thread, since there's other 2/3 questions like this with correct answers – Silvano H. Aug 05 '20 at 11:51
  • 2
    same goes for you. for these questions, you should flag as duplicate and move on. questions with answers might not be deleted by the automatic cleanup script – Nicolas Gervais Aug 05 '20 at 11:52
  • but maybe he's new here, it's not a crime helping someone tho. – Silvano H. Aug 05 '20 at 11:57
  • Helping is a good thing. Not following rules is bad thing: you are risking to get downvotes, because answer to a duplicate question (which already have answer) is in-fact "not useful". Your answer is good and I would upvote it otherwise. – Sinatr Aug 05 '20 at 12:10
  • @SilvanoH.thanks for your answer but it doesn't work for me in C#, it also working but it didn't get me an output – Hossein Aug 05 '20 at 14:19
  • you need to output it through Console.WriteLine(string) – Silvano H. Aug 06 '20 at 08:55