Skip to content

Instantly share code, notes, and snippets.

@mornir
Last active January 5, 2018 11:53
Show Gist options
  • Save mornir/a028e39b4eef8e139c1c10f44b8da7e3 to your computer and use it in GitHub Desktop.
Save mornir/a028e39b4eef8e139c1c10f44b8da7e3 to your computer and use it in GitHub Desktop.
strings manipulations

Manipulate strings

Prepend

// optionaly check if prefix already exists
const string = 'localhost:8080'
!string.startsWith('http://') ? 'http://localhost:8080' : ''
const newString = `http://${string}`

Split at specific caracter

const name = 'Matt Damon'
const [first, last] = name.split(' ')

Remove substring from string

const string = 'http://localhost:8080'
const newString = string.replace('http://', '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment