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

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 Check if a String Contains Whitespace in Rust

In Rust, there are 2 ways to check if a string contains whitespace. Using char::is_whitespace char::is_whitespace returns true if the character has the Unicode White_Space property. You can pass char::is_whitespace to .contains(): fn main() { ...
Unused

How to Remove a Trailing Newline in Python

In Python, there are 4 ways to remove a trailing newline. Using rstrip Method The str.rstrip() method returns a copy of the string with trailing characters removed. For example, #!/usr/bin/python3 s = "\nab c\r\n" # str.rstrip([chars]) n = s....
Tomoki

How to Read a File Line-by-Line in Go

In Golang, there are 2 ways to read a file line-by-line. Using bufio.Scanner Function Scanner provides a convenient interface for reading data such as a file of newline-delimited lines of text. The ones that are currently implemented are: packa...
Sambhav Khandelwal

How To Make a For Loop and Range in Rust

In Rust, there are 3 ways to support For Loop expression.Using while Expression A while loop begins by evaluating the boolean loop conditional operand. fn main() { let mut i = 0; while i < 3 { println!("{}", i); i += 1; } // Vec ...
ada

How to print a formatted string in Rust

Rust String Formatting and Printing Best Practices.Using println! Prints to the standard output, with a newline. Use the format! syntax to write data to the standard output. See std::fmt for more information. fn main() { let name = "Bob"; pri...
aweis

How to find intersection of two slices in Go

Intersection set of golang slices.Using map cache It's a best method for intersection two slice. Time complexity is too low. Time Complexity : O(m+n) package main import "fmt" func intersection(a, b []string) ([]string, error) { // uses empty s...
Patcher56

How to find the difference between two slices in Go

Comparing two slices in Go.Using map cache Creates a slice of slice values not included in the other given slices. An implementation is shown in the section below. package main import "fmt" // difference returns the elements in `a` that aren't in ...
aweis

How many keywords are there in Go

List of Golang Keywords. Keywords The following keywords are reserved and may not be used as identifiers. break default func interface select case defer go map struct chan else goto package switch const ...
Sambhav Khandelwal