Java String Split by “|”

You must use: String [] temp = s.split(“\\|”); This is because the split method takes a regular expression, and | is one of the special characters. It means ‘or’. That means you are splitting by ” or ”, which is just ”. Therefore it will split between every character. You need two slashes because the … Read more

Case insensitive string search in golang

strings.EqualFold() can check if two strings are equal, while ignoring case. It even works with Unicode. See http://golang.org/pkg/strings/#EqualFold for more info. http://play.golang.org/p/KDdIi8c3Ar package main import ( “fmt” “strings” ) func main() { fmt.Println(strings.EqualFold(“HELLO”, “hello”)) fmt.Println(strings.EqualFold(“ÑOÑO”, “ñoño”)) } Both return true.

Extract the last word from a string using C#

Well, the naive implementation to that would be to simply split on each space and take the last element. Splitting is done using an instance method on the String object, and the last of the elements can either be retrieved using array indexing, or using the Last LINQ operator. End result: string lastWord = input.Split(‘ … Read more

Javascript String Compare == sometimes fails

Double equals is the appropriate way to compare strings in Javascript, it is returning false then there may be whitespace to the left and or right of one string. Put a .trim() on the end of the strings and my comparison should started working: var panel = response.substr(0, response.indexOf(“<“)).trim(); if(panel == “combo”){ //do something }