Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

javascript - 字符串中仅保留前n个字符?(Keep only first n characters in a string?)

Is there a way in JavaScript to remove the end of a string?(JavaScript中有没有一种方法可以删除字符串的结尾?)

I need to only keep the first 8 characters of a string and remove the rest.(我只需要保留字符串的前8个字符,然后删除其余的字符。)   ask by user978905 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are looking for JavaScript's String method substring(您正在寻找JavaScript的String方法substring)

eg(例如) 'Hiya how are you'.substring(0,8); Which returns the string starting at the first character and finishing before the 9th character - ie 'Hiya how'.(它返回从第一个字符开始并在第9个字符之前结束的字符串-即“ Hiya how”。) substring documentation(子字符串文档)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...