No fancy functions or libraries just common sense and solves your problem. It supports as many hashed words as you would like.
To demonstrate how it works I have created 1 TextBox and 1 Button in a c# form but you could use this code in console or pretty much anything.
string output = ""; bool hash = false;
foreach (char y in textBox1.Text)
{
if(!hash) //checks if 'hash' mode activated
if (y != '#') output += y; //if not # proceed as normal
else { output += '*'; hash = true; } //replaces # with *
else if (y != ' ') output += y; // when hash mode activated check for space
else { output += "* "; hash = false; } // add a * before the space
} if (hash) output += '*'; // this is needed in case the hashed word ends the sentence
MessageBox.Show(output);
and behold
Today the weather is very nice #sun
becomes
Today the weather is very nice *sun*
here is the same code but in method form for you to pop right in your code
public string HashToAst(string sentence)
{
string output = ""; bool hash = false;
foreach (char y in sentence)
{
if (!hash)
if (y != '#') output += y;
else { output += '*'; hash = true; } // you can change the # to anything you like here
else if (y != ' ') output += y;
else { output += "* "; hash = false; } // you can change the * to something else if you want
} if (hash) output += '*'; // and here also
return output;
}
to demonstrate how you could modify this below is a customizable version
public string BlankToBlank(string sentence,char search,char highlight)
{
string output = ""; bool hash = false;
foreach (char y in sentence)
{
if (!hash)
if (y != search) output += y;
else { output += highlight; hash = true; }
else if (y != ' ') output += y;
else { output += highlight+" "; hash = false; }
} if (hash) output += highlight;
return output;
}
So the search would search for the character before the word and the highlight char will surround the word. Word being defined as characters until it reaches a space or the end of the string.