I have the following main string which contains link Name and link URL. The name and url is combined with #;. I want to get the string of each link (name and url i.e. My web#?http://www.google.com), see example below
string teststring = "My web#;http://www.google.com My Web2#;http://www.bing.se Handbooks#;http://www.books.se/";
and I want to get three different strings using any string function:
- My web#?http://www.google.com
- My Web2#?http://www.bing.se
- Handbooks#?http://www.books.de
So this looks like you want to split on the space after a
#;, instead of splitting at#;itself. C# provides arbitrary length lookbehinds, which makes that quite easy. In fact, you should probably do the replacement of#;with#?first:That’s it:
If you are worried that your input might already contain other
#?that you don’t want to split on, you can of course do the splitting first (using#;in the pattern) and then loop oversubstringsand do the replacement call inside the loop.