1

I'm reading a log file using file reader and then want to do some text manipulation using javascript, to use the read data further in my program. So far I managed to split my input by lines, but now that I want to format the specific strings in the array nothing happens. Is this due to not declaring the array globally? Basically I wanted to do a for loop that checks all the strings inside my array and remove " " (four blank spaces) that appear at the start for some of my strings. This is my code

$("#draftlog").change(function() {
var logFile = $('#draftlog').get(0).files[0]; 
//gets first file from draftlog
var reader = new FileReader;
reader.readAsText(logFile);
reader.onload = function(e) {
var rawLog = reader.result;
//reads first file from draftlog as text
var re=/\r\n|\n\r|\n|\r/g;
arrayOfLines = rawLog.replace(re,"\n").split("\n");
//splits the text into an array of strings for every new line
for(x=0;x<arrayOfLines.length;x++) {
    arrayOfLines[x].replace(/    /g,'');
}
console.log(arrayOfLines);
};
});

my input will typicaly look like this:

Event #: 7952945
Time:    5.2.2015 17:14:54
Players:
    TheDoktorJot
    Arlekin
    Jokulgoblin
    Felo
    Petrolit
    Greyjoy
--> Susti
    themuse1975
    n0sfea

------ FRF ------ 

Pack 1 pick 1:
    Abzan Runemark
    Rakshasa's Disdain
    Reach of Shadows
    Grim Contest
    Aven Skirmisher
    Lotus Path Djinn
    Formless Nurturing
    Tasigur's Cruelty
    Temur Battle Rage
    Return to the Earth
--> Temur Sabertooth
    Fascination
    Jeskai Barricade
    Arcbond
    Rugged Highlands

Pack 1 pick 2:
    Sandblast
    Sultai Runemark
    Jeskai Sage
    Hooded Assassin
    Pressure Point
    Gore Swine
    Whisperer of the Wilds
    Mardu Runemark
    Ambush Krotiq
    Write into Being
    Qarsi High Priest
    Hewed Stone Retainers
    Wardscale Dragon
--> Mastery of the Unseen

1 Answer 1

3

Strings are immutable, you have to write it back

for(x=0;x<arrayOfLines.length;x++) {
    arrayOfLines[x] = arrayOfLines[x].replace(/    /g,'');
}

You could also just trim it to remove leading and following whitespace

arrayOfLines[x] = arrayOfLines[x].trim();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.