How do I add a character at a specific position in a string?

后端 未结 2 1548
不知归路
不知归路 2020-12-30 11:52

I am using Notepad++ and want to insert a character at a specific position in a string using regular expression replacement.

What would the expressions be to, say, i

2条回答
  •  感动是毒
    2020-12-30 12:31

    Also using Vanilla Javascript

    var str = 'USDYEN'
    // add a / in between currencies
    // var newStr = str.slice(0, 3) + ' / ' + str.slice(3)
    
    // var newStr = str.slice(3) // removes the first 3 chars
    // var newStr = str.slice(0,3) // removes the last 3 chars
    var newStr = str.slice(0,3) + ' / ' + str.slice(3) // removes the first 3 and adds the last 3
    
    console.log(newStr)
    

    More information how to use slice()

    https://www.w3schools.com/jsref/jsref_slice_string.asp

提交回复
热议问题