I have the following string
Brad Thorm signs for the <hash>All Blacks</hash>
It may not be “All Blacks” between the tags, It could be anything. I need to parse this string such that when the <hash></hash> tags are encountered:
- Remove all spaces from the string between the tags, i.e. “All Blacks” should become “AllBlacks”
- Add a “#” symbol to the front of the string between the tags, i.e. “AllBlacks” becomes “#AllBlacks”
Looking for the cleanest way to do this.
Reworking Chris’ code into a function and looping the array, this works for multiple hash instances within the provided string:
Pass the string to convert into the function and you’re done: