How can I trim beginning and ending double quotes from a string?

You can use String#replaceAll() with a pattern of ^\”|\”$ for this. E.g. string = string.replaceAll(“^\”|\”$”, “”); To learn more about regular expressions, have al ook at http://regular-expression.info. That said, this smells a bit like that you’re trying to invent a CSV parser. If so, I’d suggest to look around for existing libraries, such as OpenCSV.

How to remove whitespace from right end of NSString?

UPDATE: A quick benchmark showed that Matt’s own adaption, based on Max’ & mine, performs best. @implementation NSString (TrimmingAdditions) – (NSString *)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet *)characterSet { NSUInteger location = 0; NSUInteger length = [self length]; unichar charBuffer[length]; [self getCharacters:charBuffer]; for (location; location < length; location++) { if (![characterSet characterIsMember:charBuffer[location]]) { break; } } return [self substringWithRange:NSMakeRange(location, length … Read more

Faster way to remove ‘extra’ spaces (more than 1) from a large range of cells using VBA for Excel

Late to the party but… There is no need for iteration through cells/values nor a recursive function to search and replace multiple spaces in a range. Application.Trim wil actually take care of multiple spaces between words (and will trim leading/trailing spaces) leaving single spaces in between words intact. The great thing about it, is that … Read more

Trim characters in Java

Apache Commons has a great StringUtils class (org.apache.commons.lang.StringUtils). In StringUtils there is a strip(String, String) method that will do what you want. I highly recommend using Apache Commons anyway, especially the Collections and Lang libraries.

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

Trim spaces from end of a NSString

Taken from this answer here: https://stackoverflow.com/a/5691567/251012 – (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet { NSRange rangeOfLastWantedCharacter = [self rangeOfCharacterFromSet:[characterSet invertedSet] options:NSBackwardsSearch]; if (rangeOfLastWantedCharacter.location == NSNotFound) { return @””; } return [self substringToIndex:rangeOfLastWantedCharacter.location+1]; // non-inclusive }