I've got this script:
$.get('file.txt', function(x) {
var i;
var pos = 0;
var availableTags = [];
x = x.split(/[\;,\n]+/);
for (i = 0; i < x.length; i = i + 2)
availableTags[pos++] = x[i];
console.log(availableTags);
$(function() {
$("#search").autocomplete({
source: availableTags
});
});
}, 'text');
I want it to read the first column of this file.txt
Supermarket;big shop where a wide range of products is sold
Station;a place where you can take a train, a bus, etc.
School;place where students learn
Though commas are not spliters, the script understands they are, and after the commas "," of the second line the reading is mistaken, as it understand bus, etc as items. Any suggestion?
Just remove the comma from the reg-exp x = x.split(/[\;\n]+/); because your regular-expression is splitting the string based on both ; &,.
Below is the corrected code
JS CODE:
$.get('file.txt', function(x) {
var i;
var pos = 0;
var availableTags = [];
x = x.split(/[\;\n]+/); //removed ',' from regular-expression
for (i = 0; i < x.length; i = i + 2){
availableTags[pos++] = x[i];
}
console.log(availableTags);
$(function() {
$("#search").autocomplete({
source: availableTags
});
});
}, 'text');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With