Enter a character in a String in the position i

0

Hi, I have a project but I'm stuck in a couple of lines. I'm interested, as the title says, to enter a character in a position of some new chain.

The program what it does is that it is printing characters but I want them to be saved in a chain 1 to 1 in position 0, 1, 2, ... until the end of the for I am using.

for(int i=0; i<data.length(); i++){  
      int Ascii=Dia;
      Ascii= Ascii + data.charAt(i);
      for(int k=8, Pot ; k>=0; k--){
            Pot=(int) Math.pow(2, k);
            if(Ascii>=Pot){
                System.out.print("1");
                Ascii=Ascii-Pot;
            }else{
                System.out.print("0")
            }              
       }
}

In the code that I share, I would like to modify the system.out that is inside the if and modify it to save it in a chain one by one. In another part of the program I do the same but this time it's a char instead of a number

    
asked by Alejo 26.09.2018 в 03:57
source

1 answer

0

Pruba with this method

private String intoString(String textoReal, String textoInsert, int pos){
        StringBuilder stringBuilder= new StringBuilder(textoReal);
        stringBuilder.insert(pos,textoInsert);
        return stringBuilder.toString();
    }

Where real text is your text .... textoInsert is the text that you are going to insert and pos is the position where you are going to enter textInsert in textReal .. Greetings and I hope it helps you in something

    
answered by 26.09.2018 в 19:48