Skip to content

Instantly share code, notes, and snippets.

@AbudiMutamba
Created July 6, 2021 10:40
Show Gist options
  • Save AbudiMutamba/5ad62674aee8f71ab6df2bd1955fbf22 to your computer and use it in GitHub Desktop.
Save AbudiMutamba/5ad62674aee8f71ab6df2bd1955fbf22 to your computer and use it in GitHub Desktop.
Ablestate Corhort 1 javascript session
console.clear();
//console.log("test");
/**
* string.substr(start[, lenght]): Extracted a portion of a string beginning from start and ending at start plus length.
* The return is the extraction begins from the end of the string.
* If start is out of bounds or greater than the string.lenght an empty string will be returned.
* If you don't specify the lenght but specify the start then the return from the start to the end of the string.
* If you dont specify the beginning and end or if you don't specify arguments it returns the entire string.
*
*/
let olunyiliri = `Buganda kifo kili mu masekati ge'gwanga eliyitibwa Uganda`;
console.log(olunyiliri.length)
let buganda = olunyiliri.substr(0, 7);
console.log(buganda);
let ekifo= olunyiliri.substr(8, 4);
console.log(ekifo);
let sikitufu = olunyiliri.substr(70, 5);
console.log(sikitufu);
let extractUganda = olunyiliri.substr(-6);
console.log(extractUganda);
let extractFrom21 = olunyiliri.substr(21);
console.log(extractFrom21);
let examiningWithOutArgs = olunyiliri.substr();
console.log(examiningWithOutArgs);
/**
* string.substring(indexA [, indexB])
* Get a subset string from a given string based on index A and index B. Index B is optional.
* If we specify -8 value for IndexA we get the entire string back.
*/
let getKifo = olunyiliri.substring(8, 12);
console.log(getKifo);
let getFromIndex8 = olunyiliri.substring(8);
console.log(getFromIndex8);
let getFromNegative = olunyiliri.substring(-8);
console.log(getFromNegative);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment