I have a string of 200 characters (max) which is divided into several different zones, for example in position 101 on 30 characters I have the name of the article, in position 16 on 2 characters the theme (it is also necessary to respect the framing on the right or on the left in the zone as well as the characteristics of completion) etc… I have to update or insert values in this string at different positions. I had a java function that I was using in Talend Open Studio but I don’t know how to translate that into js and especially into N8N
Thank you for your suggestions
here is my java code :
public static String xpositionne(String chaine,Integer debut,Integer longueur,String variable,Boolean cadredroite,String caraComp){
String variableNew="";
Integer variableLength=0;
String chaineL="";
String chaineR="";
Integer chaineLength=0;
variableLength=variable.length();
System.out.println("chaine :"+chaine);
System.out.println("variable : "+variable);
System.out.println("variablelenght : "+variableLength);
chaineLength=chaine.length();
variableNew=variable;
if(longueur<variableLength){
variableNew=variable.substring(0,longueur-1);
}
if(longueur>variableLength){
if(cadredroite){
for(int i=1;i<=(longueur-variableLength);i++){
variableNew=caraComp+variableNew;
}
}
if(cadredroite==false){
for(int i=1;i<=(longueur-variableLength);i++){
variableNew+=caraComp;
}
}
}
chaineL=chaine.substring(0,debut-1);
chaineR=chaine.substring((debut-1)+longueur,chaineLength);
return (chaineL+variableNew+chaineR);
}