Charset Conversion € \x80

33 views Asked by At

I'm sure I'm missing something obvious here but I have a string that at a certain point has the and I know that this means the next section repeats 128 times or if the character is 7 then it repeats 55 times.

So a basic function would be like such :

function GetMultiplier(str){ 
    var M = (/XXX(.)/g).exec(str)[1]; // Where the separator is 'XXX' for example
    if(M=="€") return 128; 
    else if(M=="7") return 55; 
    else return undefined; 
}; 

GetMultiplier('abc123XXX€helloworld'); \\ Would return 128 

So basically I need this but no mater what comes after the separator it will return a numeric value.

HERE is the link to the charsets that I'm using to manually decode this.

Sorry for the bad explanation.

1

There are 1 answers

0
gog On

Use match instead of exec and drop the /g:

function GetMultiplier(str){ 
    var M = str.match(/XXX(.)/)[1];
    if(M=="€") return 128; 
    else if(M=="7") return 55; 
    else return undefined; 
}; 

a = GetMultiplier('abc123XXX€helloworld'); 
console.log(a)