JavaScript Obtenha os 10 primeiros caracteres de string
var str = "Hello world That is reallly neat!";
var res = str.substring(0, 5);//get first 5 chars
Grepper
var str = "Hello world That is reallly neat!";
var res = str.substring(0, 5);//get first 5 chars
const string = "0123456789";
console.log(string.slice(0, 2)); // "01"
console.log(string.slice(0, 8)); // "01234567"
console.log(string.slice(3, 7)); // "3456"
const str = 'Mozilla';
console.log(str.substring(1, 3));
// expected output: "oz"
console.log(str.substring(2));
// expected output: "zilla"
# To find the index of a substring in another string
# Take for instance, below take two strings: str and substr.
str="hello world"
substr="world"
prefix=${str%%$substr*}
index=${#prefix}
if [[ index -eq ${#str} ]];
then
echo "Substring is not present in string."
else
echo "Index of substring in string : $index"
fi
var str = "The MEAN stack is MongoDB, Express.js, AngularJS, and Node.js";
str.indexOf('MongoDB') !== -1 // true
str.indexOf('Java') !== -1 //false
str.indexOf('Node', 5) !== -1 //true
/*Delimiter variables, first and second position*/
DECLARE @dfp AS CHAR(1);
DECLARE @dsp AS CHAR(1);
DECLARE @text VARCHAR(MAX);
SET @dfp = ';';
SET @dsp = '@';
SET @text = 'I want you to ;Extract this@ substring for me please.';
SELECT SUBSTRING(@text, (CHARINDEX(@dfp, @text) + 1), (CHARINDEX(@dsp, @text) - 2) - CHARINDEX(@dfp, @text) + Len(@dsp))