How to convert comma-separated String to List?

Convert comma separated String to List List<String> items = Arrays.asList(str.split(“\\s*,\\s*”)); The above code splits the string on a delimiter defined as: zero or more whitespace, a literal comma, zero or more whitespace which will place the words into the list and collapse any whitespace between the words and commas. Please note that this returns simply … Read more

To switch from vertical split to horizontal split fast in Vim

Vim mailing list says (re-formatted for better readability): To change two vertically split windows to horizonally split Ctrl–w t Ctrl–w K Horizontally to vertically: Ctrl–w t Ctrl–w H Explanations: Ctrl–w t makes the first (topleft) window current Ctrl–w K moves the current window to full-width at the very top Ctrl–w H moves the current window … Read more

How do I split a string with multiple separators in JavaScript?

Pass in a regexp as the parameter: js> “Hello awesome, world!”.split(/[\s,]+/) Hello,awesome,world! Edited to add: You can get the last element by selecting the length of the array minus 1: >>> bits = “Hello awesome, world!”.split(/[\s,]+/) [“Hello”, “awesome”, “world!”] >>> bit = bits[bits.length – 1] “world!” … and if the pattern doesn’t match: >>> bits … Read more

Split Strings into words with multiple word boundary delimiters

re.split() re.split(pattern, string[, maxsplit=0]) Split string by the occurrences of pattern. If capturing parentheses are used in pattern, then the text of all groups in the pattern are also returned as part of the resulting list. If maxsplit is nonzero, at most maxsplit splits occur, and the remainder of the string is returned as the … Read more

Split a String into an array in Swift?

Just call componentsSeparatedByString method on your fullName import Foundation var fullName: String = “First Last” let fullNameArr = fullName.componentsSeparatedByString(” “) var firstName: String = fullNameArr[0] var lastName: String = fullNameArr[1] Update for Swift 3+ import Foundation let fullName = “First Last” let fullNameArr = fullName.components(separatedBy: ” “) let name = fullNameArr[0] let surname = fullNameArr[1]

How to split a string into an array in Bash?

IFS=’, ‘ read -r -a array <<< “$string” Note that the characters in $IFS are treated individually as separators so that in this case fields may be separated by either a comma or a space rather than the sequence of the two characters. Interestingly though, empty fields aren’t created when comma-space appears in the input … Read more