Hey guys, I haven’t been able to find a good answer for what I’m trying to do:
I have a large string that can contain anywhere from 6-18 lines of text. What I want to do is replace a single line in that larger string; sometimes the line I want to replace will appear in the larger string more than once, and it will typically never be in the same position (ie. it won’t always be the first line in the larger string or second line, ect.). Otherwise I want to keep the larger string intact, just have that one line of text removed from it, I iterate over this in my bot.
I’ve tried using regex but if there are duplicates this will remove multiple lines, I’ve also tried splitting before and after the line of text but again if there are duplicates this seems to return a blank value when splitting. Is there any easy way to tell regex or any replace function to only replace a single or first instance? Or use substring/ joins to do this?
Above is an example and in the bot that value will be contained inside of a string. What I want to do is replace one instance of “0001|ABBA|9876|0393” with “”. I need the rest of the string left intact including the second instance of the string that I am removing.
Also the string I’m trying to replace will not always be in the same positions each time. For example it could be this as my starting point:
I basically have the line I want and I’m matching it to the larger string, if a match is found I need to remove that match from the larger string but only a single instance of that match because there will be another line I have that will match with, in this case, the second instance of that same string.
You know what, I was just thinking I could just count the number of instances of the line in the larger string prior to regex-ing it out and then just add back more instances of that same line into the larger string, but that kind of seems like a dumb workaround for something there’s got to be a simple streamlined solution to.