Get the character between first 2 special character in SQL

This would be my approach: SELECT CAST(‘<x>’ + REPLACE(data,’_’,'</x><x>’) + ‘</x>’ AS XML).value(‘/x[2]’,’int’) FROM YourTable First you transform this to an XML and then you pick the second node.. EDIT: Some more examples where this approach is usefull: CROSS APPLY: You can use this approach to get several tokens at once DECLARE @tbl TABLE(separated VARCHAR(100)); … Read more

Find all locations of substring in NSString (not just first)

You can use rangeOfString:options:range: and set the third argument to be beyond the range of the first occurrence. For example, you can do something like this: NSRange searchRange = NSMakeRange(0,string.length); NSRange foundRange; while (searchRange.location < string.length) { searchRange.length = string.length-searchRange.location; foundRange = [string rangeOfString:substring options:0 range:searchRange]; if (foundRange.location != NSNotFound) { // found an occurrence … Read more

Python: How to check a string for substrings from a list? [duplicate]

Try this test: any(substring in string for substring in substring_list) It will return True if any of the substrings in substring_list is contained in string. Note that there is a Python analogue of Marc Gravell’s answer in the linked question: from itertools import imap any(imap(string.__contains__, substring_list)) In Python 3, you can use map directly instead: … Read more

Get value of a string after last slash in JavaScript

At least three ways: A regular expression: var result = /[^/]*$/.exec(“foo/bar/test.html”)[0]; …which says “grab the series of characters not containing a slash” ([^/]*) at the end of the string ($). Then it grabs the matched characters from the returned match object by indexing into it ([0]); in a match object, the first entry is the … Read more