javascript - javascript remove a exact index character from the string
问题描述
let test = 'This is the test string';
console.log(test.substr(3));
console.log(test.slice(3));
console.log(test.substring(3));
Theese methods are removing first 3 character. But i want to remove only third character from the string.
The log has to be: ' Ths is the test string'
İf you help me i will be glad. All examples are giving from the substr, slice eg. eg. Are there any different methods?
解决方案
First, get the first 3
chars, then add chars 4-end
, connect those to get the desired result:
let test = 'This is the test string';
let res = test.substr(0, 2) + test.substr(3);
console.log(res);
Since substr
uses the following parameters
Start The index of the first character to include in the returned substring.
Length Optional. The number of characters to extract.
If length is omitted, substr() extracts characters to the end of the string.
We can use test.substr(3)
to get from the 3'th to the last char without specifying the length of the string
推荐阅读
- numpy - 在每个元素上使用带有函数的 Numpy.where()
- firebase - 带有 StreamBuilder 的 Firestore
- apache-kafka - 无法列出 Kafka 主题
- mips - 我如何让这个程序显示而不是三个?
- c# - IAsyncDisposable 参考实现错误?
- jmsserializerbundle - JMS 序列化程序中 DateTime 的默认反序列化格式
- excel - 如何使用索引函数获得总和
- c - 变量在 for 循环中被 crypt() 意外覆盖
- flutter - 如何在返回 NetworkImage 之前显示加载指示器?
- python - Python dash - 如何突出显示/加粗一行中的特定单词