changing the delimiter for cin (c++)

It is possible to change the inter-word delimiter for cin or any other std::istream, using std::ios_base::imbue to add a custom ctype facet. If you are reading a file in the style of /etc/passwd, the following program will read each :-delimited word separately. #include <locale> #include <iostream> struct colon_is_space : std::ctype<char> { colon_is_space() : std::ctype<char>(get_table()) {} … Read more

How do I use a delimiter with Scanner.useDelimiter in Java?

The scanner can also use delimiters other than whitespace. Easy example from Scanner API: String input = “1 fish 2 fish red fish blue fish”; // \\s* means 0 or more repetitions of any whitespace character // fish is the pattern to find Scanner s = new Scanner(input).useDelimiter(“\\s*fish\\s*”); System.out.println(s.nextInt()); // prints: 1 System.out.println(s.nextInt()); // prints: … Read more

Delimiters in MySQL

Delimiters other than the default ; are typically used when defining functions, stored procedures, and triggers wherein you must define multiple statements. You define a different delimiter like $$ which is used to define the end of the entire procedure, but inside it, individual statements are each terminated by ;. That way, when the code … Read more

SQL split values to multiple rows

If you can create a numbers table, that contains numbers from 1 to the maximum fields to split, you could use a solution like this: select tablename.id, SUBSTRING_INDEX(SUBSTRING_INDEX(tablename.name, ‘,’, numbers.n), ‘,’, -1) name from numbers inner join tablename on CHAR_LENGTH(tablename.name) -CHAR_LENGTH(REPLACE(tablename.name, ‘,’, ”))>=numbers.n-1 order by id, n Please see fiddle here. If you cannot create … Read more