“Comment tronquer la chaîne en javascript” Réponses codées

JavaScript tronquer la chaîne

var string = "ABCDEFG";
var truncString = string.substring(0, 3); //Only keep the first 3 characters
console.log(truncString); //output: "ABC"
TC5550

Tronquer un javascript de chaîne

function truncateString(str, num) {
  return str.length > num ? str.slice(0, num) + "..." : str;
}
Angry Alpaca

JavaScript troncate String Full Word

const truncate = (str, max, suffix) => str.length < max ? str : `${str.substr(0, str.substr(0, max - suffix.length).lastIndexOf(' '))}${suffix}`;

// Example
truncate('This is a long message', 20, '...'); 
Batman

Comment tronquer la chaîne en javascript

function truncateString(str, num) {
  if (str.length > num) {
    return str.slice(0, num) + "...";
  } else {
    return str;
  }
}
Important Impala

Tronquer une chaîne

function truncateString(str, num) {
 
  if (str.length > num) {
    return str.slice(0, num) + "...";
  } else {
    return str;
  }
}

truncateString("Lorem Ipsum placeholder text in any number of characters, words sentences or paragraphs", 9)  // returns Lorem Ips...
Attractive Albatross

tronquer la chaîne en javascript

_.truncate('hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there, neighbo...' 

_.truncate('hi-diddly-ho there, neighborino', {  'length': 24,  'separator': ' '});
// => 'hi-diddly-ho there,...' 

_.truncate('hi-diddly-ho there, neighborino', {  'length': 24,  'separator': /,? +/});
// => 'hi-diddly-ho there...' 

_.truncate('hi-diddly-ho there, neighborino', {  'omission': ' [...]'});
// => 'hi-diddly-ho there, neig [...]'
Light Ladybird

Réponses similaires à “Comment tronquer la chaîne en javascript”

Questions similaires à “Comment tronquer la chaîne en javascript”

Plus de réponses similaires à “Comment tronquer la chaîne en javascript” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code