Negative Offsets to Indicate Reverse List Searches?
jjweimer
I might ask that the optional OFFSET parameter in such functions as RemoveListItem accept a NEGATIVE value to indicate a search that should go backward along the list. I could then parse backward to remove the DATESTAMP in the string below without having to query the randomly unknown number of items in the string. The use of INF does not seem to work here?
newstring = RemoveListItem(0,"SomeFileName_withthisblabla_DATESTAMP","_",-1)
// newstring <-- "SomeFileName_withthisblabla"
// newstring <-- "SomeFileName_withthisblabla"
You know about the RemoveEnding function, right?
April 15, 2021 at 10:20 am - Permalink
Yes. I'll try again. It seemed I tried with wildcards "_*" as the ending string with no luck. In my case, DATESTAMP is not a fixed value.
April 15, 2021 at 10:35 am - Permalink
In reply to Yes. I'll try again. It… by jjweimer
Then RemoveEnding won't help for that.
April 15, 2021 at 10:38 am - Permalink
In spite of its name (which tells you what the author thought you would use it for) the ParseFilePath() function is useful for any sort of list. You would use something like
newstring = ParseFilePath(1,"SomeFileName_withthisblabla_DATESTAMP", "_", 1, 0)
I use this frequently for parsing subwindow names and I have used it for just the sort of thing you are talking about.
It's possible that others here at WaveMetrics might object, saying that it really is intended for file paths, but in fact it is so generally written that it is useful for a whole host of things.
April 15, 2021 at 11:05 am - Permalink
I'd thought of parsefilepath as a substitute. Thanks. That helps!
April 15, 2021 at 11:26 am - Permalink
You could use something like below for removing a regex from a end of a string.
///
/// In case the regular expression does not match, the string is returned unaltered.
///
/// See also `DisplayHelpTopic "Regular Expressions"`.
Function/S RemoveEndingRegExp(str, endingRegExp)
string str, endingRegExp
string endStr
if(strlen(str) == 0 || strlen(endingRegExp) == 0)
return str
endif
SplitString/E="(" + endingRegExp + ")$" str, endStr
return RemoveEnding(str, endStr)
End
April 15, 2021 at 01:22 pm - Permalink
Hi Thomas,
To prove I follow the discussions on the board carefully, I will quote I think from John Weeks "I solved the problem using regex and now I have two problems."
Andy
April 15, 2021 at 03:55 pm - Permalink
Which was if I believe correctly his response to my own proposal to use REGEX to solve a different problem.
April 15, 2021 at 05:58 pm - Permalink
...and I got that joke from Jim Prouty. I don't know if he made it up, or heard it somewhere else. But here is something I found by googling that phrase:
https://blog.codinghorror.com/regular-expressions-now-you-have-two-prob…
April 16, 2021 at 10:09 am - Permalink