If strings are immutable in .NET, then why does Substring take O(n) time?

UPDATE: I liked this question so much, I just blogged it. See Strings, immutability and persistence The short answer is: O(n) is O(1) if n does not grow large. Most people extract tiny substrings from tiny strings, so how the complexity grows asymptotically is completely irrelevant. The long answer is: An immutable data structure built … Read more

How to extract the substring between two markers?

Using regular expressions – documentation for further reference import re text=”gfgfdAAA1234ZZZuijjk” m = re.search(‘AAA(.+?)ZZZ’, text) if m: found = m.group(1) # found: 1234 or: import re text=”gfgfdAAA1234ZZZuijjk” try: found = re.search(‘AAA(.+?)ZZZ’, text).group(1) except AttributeError: # AAA, ZZZ not found in the original string found = ” # apply your error handling # found: 1234

Extract substring in Bash

You can use Parameter Expansion to do this. If a is constant, the following parameter expansion performs substring extraction: b=${a:12:5} where 12 is the offset (zero-based) and 5 is the length If the underscores around the digits are the only ones in the input, you can strip off the prefix and suffix (respectively) in two … Read more

What is the difference between substr and substring?

The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to return. Links? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring

What is the difference between String.slice and String.substring?

slice() works like substring() with a few different behaviors. Syntax: string.slice(start, stop); Syntax: string.substring(start, stop); What they have in common: If start equals stop: returns an empty string If stop is omitted: extracts characters to the end of the string If either argument is greater than the string’s length, the string’s length will be used … Read more

How do I check if string contains substring? [duplicate]

Like this: if (str.indexOf(“Yes”) >= 0) …or you can use the tilde operator: if (~str.indexOf(“Yes”)) This works because indexOf() returns -1 if the string wasn’t found at all. Note that this is case-sensitive. If you want a case-insensitive search, you can write if (str.toLowerCase().indexOf(“yes”) >= 0) Or: if (/yes/i.test(str)) The latter is a regular expression … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)