Issue
I have some typescript code that reads 5 players from a text file. The problem is I am unable to remove the word "player - " from all of them?
Example of the text file:
player - toby
player - coby
player - roby
player - poby
player - boby
Here is the code I wrote:
const players = fs
.readFileSync(`${__dirname}/db/players.txt`, {
encoding: 'utf8',
flag: 'r',
})
.toString().replace('player - ',"")
.split('\n');
but it only is replacing for one person?
Solution
You can try with regex to do it
.readFileSync(`${__dirname}/db/players.txt`, {
encoding: 'utf8',
flag: 'r',
})
.toString().replace(/player - /g,"")
.split('\n');
Answered By - lucumt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.