Trocar valor de um String por outra

2 respostas
C

Galera to tentando faze o seguinte

String c = “01100”;

gostaria de troca um bit so dessa string, ficando assim c = " 01000", troquei somente o terceiro bit,
tentei usao replace mas ele substitui todos os 1 por 0 e gostaria q somente o terceiro bit trocasse

vlww

2 Respostas

Marlon_Meneses

isso resolve

String c = "01100"; char aux[] = c.toCharArray(); aux[2] = '0'; System.out.print(aux);

C

vlw… consegui fazendo assim tb

String a = "01100";
char b[] = a.toCharArray(); 
int aleat = 4;
double num = ((int)aleat*Math.random());
int c = (int)num;
b[c]= '4';		
String str = new String(b);
System.out.println(str);

é pq eu preciso q volte pra um string depois

vlww pela ajuda

Criado 11 de março de 2008
Ultima resposta 11 de mar. de 2008
Respostas 2
Participantes 2