Logo

dev-resources.site

for different kinds of informations.

W3Schools Strings Method With Example

Published at
8/18/2022
Categories
javascript
strings
code
example
Author
developedbyjk
Categories
4 categories in total
javascript
open
strings
open
code
open
example
open
Author
13 person written this
developedbyjk
open
W3Schools Strings Method With Example

Here are Strings Method that I learned on W3schools
you can copy paste it and check the output and experiment with it

/*
IN JAVASCRIPT
strings are primitve values and they dont have mehthod or properties
BUT
JS consider stings as objects so  we can use mehthod and properties with Srings


*/

let text = "Hello World Hello";

//returns the lenght of the text
console.log(text.length);

//extracting the strings from inde
console.log(text.slice(2,5));

//extracting the string if its negative then starts from back
console.log(text.slice(-1,));

//extractin the string : (from, no of amount to extract);
console.log(text.substr(2, 6));

//replace the specific World
console.log(text.replace("Hello","Bye"));
/*
if we have text as >>>>> "Hellow my world you are hello"
:  text.replace("Hello","bye"); >> will replace only 1st hello
: to replace all 'Hello' we use : text.replace("/Hello/g","bye");

*/

console.log(text.replace("/Hello/g","bye"));
// or we can use

console.log(text.replaceAll("Hellow", "bye"));

//to upper case
console.log(text.toUpperCase());

// to lower case
console.log(text.toLowerCase());

// now its time to trim so
console.log("TRIMMING  " +  text.trim());

// adding some before num
//if its nume first we need to convet it into strings
let padnum = "hey bitch";
let convert = padnum.toString();
let padstart = convert.padStart(10,"o");
console.log(padstart);

//SAme you can do with pad end
var name = "bhag";
let outputofname = name.padEnd(50," bhai ");
console.log(outputofname);

//Extracting String Character at specific position
console.log(text.charAt(9));

//Extracting String Character code at specific position
console.log(text.charCodeAt(9));

// you can also do this
console.log(text[9]);

//Converting String to arrays 
var convertedtoarray = text.split(" ");
console.log(convertedtoarray[2]);
Enter fullscreen mode Exit fullscreen mode
strings Article's
30 articles in total
Favicon
trimMiddle() - the missing String trim method
Favicon
Interpolação, Verbatim String Literals, Múltiplas Linhas – Tudo Sobre Strings no C#
Favicon
Leetcode — 3110. Score of a String
Favicon
Tipos Básicos em Kotlin - String Literals
Favicon
Tipos Básicos em Kotlin - Strings
Favicon
Quick Zig and C String Conversion Conundrums
Favicon
Code Smell 261 - DigiCert Underscores
Favicon
JavaScript: Strings, String Methods, and String Properties
Favicon
JavaScript: String Template Literals
Favicon
Top 7 PHP Strings Interview Questions and Answers
Favicon
Strings in java language
Favicon
Strings in java language
Favicon
Unraveling the Power of Strings in Python
Favicon
What to use instead of `@ember/string`
Favicon
JS Challenge: Check if a string is a palindrome
Favicon
5 Interesting Things About Strings in Java
Favicon
Efficient String Splitting in Go: A Solution for Gophers Dealing with API Responses
Favicon
Javascript : 12 méthodes essentielles pour les chaînes de caractères
Favicon
anagram program in java
Favicon
How to convert String to Integer in java
Favicon
JS Blog - String Manipulation
Favicon
Find the Index of the First Occurrence in a String (Naive and KMP Solutions)
Favicon
In search of subsequence
Favicon
383. Ransom Note
Favicon
Split and Join: The Dichotomy of Strings and Arrays
Favicon
How do Bytes live in Solidity and coexist with Strings?
Favicon
"str and String in Rust confuses a lot of people in the beginning"
Favicon
W3Schools Strings Method With Example
Favicon
Javascript Tagalog - Strings
Favicon
Resources(R.string) in viewModel in Android

Featured ones: