.net - How to delete certain characters of a word in c# -


i have a

string word = "degree/nn"; 

what want remove "/nn" part of word , take word "degree".

i have following conditions:

  • the length of word can different in different occasions. (can word therefore length not fixed)
  • but word contain "/nn" part @ end always.

how can in c# .net?

implemented extension method:

static class stringextension {   public static string removetrailingtext(this string text, string texttoremove)   {     if (!text.endswith(texttoremove))       return text;      return text.substring(0, text.length - texttoremove.length);   } } 

usage:

string whatever = "degree/nn".removetrailingtext("/nn"); 

this takes account unwanted part "/nn" removed end of word, specified. simple replace remove every occurrence of "/nn". however, might not problem in special case.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -