All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Format a Currency with Commas in Golang

Formatting float to currency string in Go. Using localized formatting Use golang.org/x/text/message to print using localized formatting for any language in the Unicode CLDR. Make a main.go file containing the following: package main import ( "...
Unused

How to Delete a Character from a String in Python

In Python, there are 2 ways to delete a character from a string. Using replace Method The str.replace(old, new[, count]) method returns a copy of the string with all occurrences of substring old replaced by new. If the optional argument count is giv...
Unused

How to Get the Psition of a Character in Python

In Python, there are 3 ways to get the position of a character. Using find Method The str.find(sub[, start[, end]]) method returns the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start an...
aweis

How to Remove all Whitespace in a String in Python

In Python, there are 3 ways to remove all whitespace in a string. Using str.replace Function The str.replace(x) function returns a copy of the string with all occurrences of substring old replaced by new. See the following example: #!/usr/bin/p...
pooriabt

How to Index Characters in a String in Go

In Golang, there are 2 ways to index characters in a string. Using individual characters In UTF-8, ASCII characters are single-byte corresponding to the first 128 Unicode characters. Strings behave like slices of bytes. A rune is an integer value i...
Patcher56

How to Count the Occurrences of a List Item in Python

In Python, there are 3 ways to count the occurrences of a list item. Using count Method The str.count() method returns the number of non-overlapping occurrences of substring sub in the range [start, end]. Optional arguments start and end are interpr...
Patcher56

How to Split a String in Rust

In Rust, there are 3 ways to split a string. Using split Function An iterator over substrings of this string slice, separated by characters matched by a pattern. See the following example: fn main() { let s = "abc1bcd2e"; let _split = s.sp...
ada

How to check if string contains substring in Rust

In Rust, there are 3 ways to check if string contains substring.Using String contains Function The easiest way to check if a Rust string contains a substring is to use String::contains method. The contains method Returns true if the given pattern m...
Tomoki

How to split a string into a slice in Go

Splitting a String into a Slice in Golang.Using strings.Split Function Use the strings.Split function to split a string into its comma separated values. package main import ( "fmt" "strings" ) func main() { s := "Japan,Germany" // func S...
Unused

How to check if string contains substring in Python

Does Python have a string 'contains' substring method?.Using the in Operator The easiest way to check if a Python string contains a substring is to use the in operator. str = "Python" if "th" in str: print("Found!") # case-insensitive if "TH" no...
Patcher56

How to get a substring from a string in Go

Extracting substrings in Go.Using the slice syntax A slice is formed by specifying two indices, a low and high bound, separated by a colon: // a[low : high] s := "Hello,世界" // e fmt.Println(s[1:2]) fmt.Println(s[1:]) // Hello,世界 fmt.Println(s[:]) ...
Patcher56

How to check if a string contains a substring in JavaScript

How do you check if a string contains a substring?.Using String.prototype.includes The includes() method performs a case-sensitive search to determine whether one string may be found within another string, returning true or false as appropriate. 'Go...
pooriabt

How to check if string contains a substring in Go

Go test string contains substring.Using strings.Contains Function How do I check if a string is a substring of another string in Go? Use the function Contains from the strings package. Contains function returns a boolean value. It returns true if the...
Tomoki