I got a question in vb.net can I identify each of the character in string for an example i got a string of "Hello!. Good Afternoon!"
from this string can i trim away the period symbol? Thank you
I got a question in vb.net can I identify each of the character in string for an example i got a string of "Hello!. Good Afternoon!"
from this string can i trim away the period symbol? Thank you
You should look at the methods of the String
class, as they support different forms of string manipulation.
At its simplest, the Replace()
method can be used to replace all occurrences of a period character with an empty string.
Alternatively, you can use the IndexOf()
method to locate a specific string (e.g. the period) and the Remove()
method to remove that character.
According to my 8-ball Magic, you actually want to :
int[]
.Code:
string Input = "....Thalassius! vero ea--*/-*/-- tempestate+- fectus";
string Output = Input;
var regex = new Regex(@"[^\w\s]|_"); // *1.
var matches = regex.Matches(Input) ;
var MatchesIndex = matches .Cast<Match>()
.Select(match => match.Index)
.ToArray(); // *2.
int last = 0;
List<int> toDelete = new List<int>();
for (int i = 0; i < MatchesIndex.Length; i++) // *3.
{
if ( MatchesIndex[i] == last + 1)
toDelete.Add(MatchesIndex[i]);
last = MatchesIndex[i];
}
foreach (int i in toDelete.OrderByDescending(x => x)) // *4.
Output = Output.Remove(i, 1);
Console.WriteLine("Input : " + Input);
Console.WriteLine("Output : " + Output);
You can learn more about the regex used, thanks to @John Kugelman.