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 Get correct file base name in Golang

Golang path and filepath Examples. Using filepath.Base The number is the index of the last slash in the string. If you want to get the file's base name, use filepath.Base: package main import ( "fmt" "path/filepath" ) func main() { path ...
Patcher56

How to Use Strings in Golang

Introduction to Strings in Go.What is a String? A string is an immutable sequence of bytes. Strings may contain arbitrary data, including bytes with value 0, but usually they contain human-readable text. Make a main.go file containing the following...
ada

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 Delete an Element from an Array in PHP

In PHP, there are 3 ways to delete an element from an array. Using unset Function The unset(mixed $var, mixed ...$vars): void function destroys the specified variables. For example, $arr = ["a", "b", "d"]; unset($arr[1]); print_r($arr); Arr...
Sambhav Khandelwal

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 Append Integer to Beginning of List in Python

In Python, there are 2 ways to append integer to beginning of list. Using insert Method The list.insert() method inserts an item at a given position. The first argument is the index of the element before which to insert. For example, #!/usr/bin...
pooriabt

How to Get Key by Value in Dictionary in Python

In Python, there are 3 ways to get key by value in dictionary. Using keys Function Basically, it separates the dictionary's values in a list, finds the position of the value you have, and gets the key at that position. The following example: #!...
aweis

How to Remove an Element from a Vector in Rust

In Rust, there are 2 ways to remove an element from a vector. Using retain Function The vec::retain() function retains only the elements specified by the predicate. For example, fn main() { let mut v = vec![1, 3, 2, 3, 4]; v.retain(|&x| x ...
aweis

How to Pipe Several Commands in Go

In Golang, there are 2 ways to pipe several commands. Using piped commands For example, this function retrieves the CPU model name using piped commands: package main import ( "fmt" "os/exec" ) func main() { cmd := "cat /proc/cpuinfo | eg...
Patcher56

How to Check If an Object Is of a Given Type in Python

In Python, there are 2 ways to check if an object is of a given type. Using isinstance Method The isinstance(object, classinfo) method returns True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtua...
Unused

How to Find the Index of an Element in a Vector in Rust

In Rust, using the position function is the easiest way to find the index of an element in a vector. Using position Method The position() method searches for an element in an iterator, returning its index. position() is short-circuiting; in other ...
pooriabt

How to Index a String in Rust

In Rust, there are 2 ways to index a string. Using as_bytes Function If the enum is C-like, then you can create a static array of each of the variants and return an iterator of references to them: fn main() { let s = "abc"; let b: u8 = s.as...
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 Update a Value in a Mutable HashMap in Rust

In Rust, there are 3 ways to update a value in a mutable HashMap. Using get_mut Method The get_mut() method returns a mutable reference to the value corresponding to the key. See the following example: use std::collections::HashMap; fn main()...
Unused