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 Select a substring in Oracle SQL up to a specific character?

Using a combination of SUBSTR, INSTR, and NVL (for strings without an underscore) will return what you want: SELECT NVL(SUBSTR(‘ABC_blah’, 0, INSTR(‘ABC_blah’, ‘_’)-1), ‘ABC_blah’) AS output FROM DUAL Result: output —— ABC Use: SELECT NVL(SUBSTR(t.column, 0, INSTR(t.column, ‘_’)-1), t.column) AS output FROM YOUR_TABLE t Reference: SUBSTR INSTR Addendum If using Oracle10g+, you can use regex … Read more