0
Good afternoon, you guys. I am using the Typescript language for the first time in a "weekend project" in developing an extension for Vscode. I’ve done research for the method documentation, but I still don’t understand where I’m going wrong. I imagine it’s a "silly" problem due to inexperience with language. What is happening is that the use of the string replace method is not actually replacing all strings taken from two vectors. The function removePalavrasSelectionCodigoPython is not removing all strings from a Python code snippet, also passed as a string by the selectedCodigo variable. Following the code:
function executaExtensaoPython(selecaoCodigo:string, formatoArquivo:string):void{
var alfabetoPython : string[] = ["#", "selfie", ".", "=", "get", "set", "(", ")", ":", ","];
var alfabetoIgnorar : string[] = [" "];
var selecaoCodigoModificada;
//Retirando palavras do alfabeto das linguagens Python e Ignorar
selecaoCodigoModificada = retiraPalavrasSelecaoCodigoPython(selecaoCodigo, alfabetoIgnorar, alfabetoPython);
console.log("\nSELEÇÃO MODIFICADA = " + selecaoCodigoModificada);
}
function retiraPalavrasSelecaoCodigoPython(selecaoCodigo : string, alfabetoIgnorar : string[], alfabetoPython : string[]) : string{
for(var i=0;i<alfabetoIgnorar.length;i++){
selecaoCodigo = selecaoCodigo.replace(alfabetoIgnorar[i], "");
}
for(var i=0;i<alfabetoPython.length;i++){
selecaoCodigo = selecaoCodigo.replace(alfabetoPython[i], "");
}
return selecaoCodigo;
}
Thank you very much, Matheus.
– Pedro Barros