When to use Unicode Normalization Forms NFC and NFD?

The FAQ is somewhat misleading, starting from its use of “should” followed by the inconsistent use of “requirement” about the same thing. The Unicode Standard itself (cited in the FAQ) is more accurate. Basically, you should not expect programs to treat canonically equivalent strings as different, but neither should you expect all programs to treat … Read more

Convert a sequence of strings to integers (Clojure)

You’re looking for Integer/parseInt. user=> (map #(Integer/parseInt %) [“1” “2” “3” “4”]) (1 2 3 4) You have to wrap Integer/parseInt in an anonymous function because Java methods aren’t functions. read-string would also work in this case: user=> (map read-string [“1” “2” “3” “4”]) (1 2 3 4) read-string reads any object from a string, … Read more

VB6 equivalent of string.IsNullOrEmpty

VB6 was designed to be easy Use If str = “” Then ‘ uninitialised, null or empty “” Strings are automatically initialized to [edit] a null string. The null string is vbNullString. But don’t worry about null strings. A VB6 null string is indistinguishable from an empty string “” for (almost) any string manipulation.

PowerShell to remove text from a string

Another way to do this is with operator -replace. $TestString = “test=keep this, but not this.” $NewString = $TestString -replace “.*=” -replace “,.*” .*= means any number of characters up to and including an equals sign. ,.* means a comma followed by any number of characters. Since you are basically deleting those two parts of … Read more

Remove all line breaks at the beginning of a string in Swift

If it is acceptable that newline (and other whitespace) characters are removed from both ends of the string then you can use let string = “\n\nBLA\nblub” let trimmed = string.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) // In Swift 1.2 (Xcode 6.3): let trimmed = (string as NSString).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) To remove leading newline/whitespace characters only you can (for example) use a regular … Read more

How to split a string into substrings of equal length

I just answered a similar question on SO and thought I can provide a more concise solution: Swift 2 func split(str: String, _ count: Int) -> [String] { return 0.stride(to: str.characters.count, by: count).map { i -> String in let startIndex = str.startIndex.advancedBy(i) let endIndex = startIndex.advancedBy(count, limit: str.endIndex) return str[startIndex..<endIndex] } } Swift 3 func … Read more