What is a good alternative of LTRIM and RTRIM in Java?

With a regex you could write: String s = … String ltrim = s.replaceAll(“^\\s+”,””); String rtrim = s.replaceAll(“\\s+$”,””); If you have to do it often, you can create and compile a pattern for better performance: private final static Pattern LTRIM = Pattern.compile(“^\\s+”); public static String ltrim(String s) { return LTRIM.matcher(s).replaceAll(“”); } From a performance perspective, … Read more

Perform Trim() while using Split()

Another possible option (that avoids LINQ, for better or worse): string line = ” abc, foo , bar”; string[] parts= Array.ConvertAll(line.Split(‘,’), p => p.Trim()); However, if you just need to know if it is there – perhaps short-circuit? bool contains = line.Split(‘,’).Any(p => p.Trim() == match);

In Haskell, how do you trim whitespace from the beginning and end of a string?

If you have serious text processing needs then use the text package from hackage: > :set -XOverloadedStrings > import Data.Text > strip ” abc ” “abc” If you’re too stubborn to use text and don’t like the inefficiency of the reverse method then perhaps (and I mean MAYBE) something like the below will be more … 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

Removing spaces from string

String input = EditTextinput.getText().toString(); input = input.replace(” “, “”); Sometimes you would want to remove only the spaces at the beginning or end of the String (not the ones in the middle). If that’s the case you can use trim: input = input.trim();

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