Reputation: 775
I would like to take the words of a sentence, if that word has in each end, the forward slash character /
For example, a string should contain spaces so may have to pull a string from something like:
Example:
"Hello /World/" --> "World"
Would I have to use regular expressions for this, if so, could you tell me how to do this please? If not, how could I do it in a really basic way?
Upvotes: 0
Views: 928
Reputation: 116178
Using Regex,
string[] results = Regex.Matches("Hello /World/ hello /universe/",@"/(.+?)/")
.Cast<Match>()
.Select(m=>m.Groups[1].Value)
.ToArray();
would return World
and universe
Upvotes: 3
Reputation: 7062
Loop through all the characters. Get the first index of / on the position find the paired last / on the position and remove anything between by creating a new string. Keep looping and find the opening and closing / until finish.
Get the first index of /, last index of / and split and string.substring() it.
Upvotes: 2