In a string like this: Last-Name — lives on a road, in south-shore.
I am trying to replace all instances of "," & "-" in to " " with only skipping the 2nd instance of "-". I then want to replace the "-" with a ",".
I have currently tried to us this:
var all = node.InnerText.Replace(","," ");
var hyph = all.Replace("—",",").Replace("-",",");
Which works... except it is replacing everything and I am needing the 2nd instance of "—" to remain while all other instances of ",", "—" & "-"'s are changed to " ". So it looks like this when it is done:
(Last, Name , lives on a road in south, shore.).
When I need it to look like: (Last Name , lives on a road in south shore).
Doing some looking around, it seems that IndexOf() is the way to go but I am unsure of how to setup my query. Would I be on the right track using something like this? Or is there a better way to go about this? To be honest I am not entirely sure and I am still learning C# so sorry if this is poorly worded or way off mark.
int position = dash.IndexOf(find);
if (position > 1)
{
return dash;
}
return dash.Substring(1, position) + replace + dash.Substring(postion + find.Length);
In every case it will be:
last name — some text here
or
last name — some-sort of text
or
last-name — more text, here
or
last name — more-text here
Where it just needs to be:
last name, some text here.
Thank you for any help!