I have a requirement.
I have a text which can contain any characters.
a) I have to retain only Alphanumeric characters b) If the word "The" is found with a space prefixed or suffixed with the word, that needs to be removed.
e.g.
CASE 1:
Input: The Company Pvt Ltd.
Output: Company Pvt Ltd
But
Input: TheCompany Pvt Ltd.
Output: TheCompany Pvt Ltd
because there is no space between The & Company words.
CASE 2:
Similarly, Input: Company Pvt Ltd. The
Output: Company Pvt Ltd
But Input: Company Pvt Ltd.The
Output: Company Pvt Ltd
Case 3:
Input: Company@234 Pvt; Ltd.
Output: Company234 Pvt Ltd
No , or . or any other special characters.
I am basically setting the data to some variable like
_company.ShortName = _company.CompanyName.ToUpper();
So at the time of saving I cannot do anything. Only when I am getting the data from the database, then I need to apply this filter. The data is coming in _company.CompanyName
and I have to apply the filter on that.
So far I have done
public string ReplaceCharacters(string words)
{
words = words.Replace(",", " ");
words = words.Replace(";", " ");
words = words.Replace(".", " ");
words = words.Replace("THE ", " ");
words = words.Replace(" THE", " ");
return words;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(ReplaceCharacters(textBox1.Text.ToUpper()));
}
Thanks in advance. I am using C#