Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display only 10 characters of a long string?

How do I get a long text string (like a querystring) to display a maximum of 10 characters, using JQuery?

Sorry guys I'm a novice at JavaScript & JQuery :S
Any help would be greatly appreciated.

like image 700
Nasir Avatar asked Aug 05 '10 13:08

Nasir


People also ask

How do I limit the length of a string?

Approach 2 (Using mb_strimwidth() function): The mb_strimwidth function is used to get truncated string with specified width. It takes as input the string and the required number of characters. The characters after it are appended with an “!!” string. It returns the string with the trimmed length.

How do I get the last 5 characters of a string?

To get the last N characters of a string, call the slice method on the string, passing in -n as a parameter, e.g. str. slice(-3) returns a new string containing the last 3 characters of the original string. Copied! const str = 'Hello World'; const last3 = str.

How do you display part of a string in JavaScript?

The substr() method extracts a part of a string. The substr() method begins at a specified position, and returns a specified number of characters. The substr() method does not change the original string. To extract characters from the end of the string, use a negative start position.


1 Answers

If I understand correctly you want to limit a string to 10 characters?

var str = 'Some very long string'; if(str.length > 10) str = str.substring(0,10); 

Something like that?

like image 91
Sebs Avatar answered Nov 15 '22 18:11

Sebs