Jump to content

Ajuda para eliminaçao de caracteres numa string


Fest
 Share

Recommended Posts

olá malta eu gostava de saber como é k eu elimino um determinado caracter de uma string sem fazer replace. na verdade o meu prob é:

se eu inserrir        A    88     

como é k faço para eliminar os espaços?? eu ja usei string.trim para tirar os espaços exteriores mas i para os interiores?? eu n posso usar o replace i ja tentei fazer com for i if dentro dele mas da erro

P.S: objectivo é k fike A88

thx a tds pelo tempo

Link to comment
Share on other sites

bem k eu gostava mas tambem n posso usar esse Xd sorry. deve haver uma maneira com if i for axu...tive a ver um site i apresenta esta resoluçao

public static String removeChar(String s, char c) {

  String r = "";

  for (int i = 0; i < s.length(); i ++) {

      if (s.charAt(i) != c) r += s.charAt(i);

      }

  return r;

}

mas o prob é k o meu caracter a eliminar n é uma letra é um espaço i eu tentei assim:

for(int i = 0; i == string.length(); i++){

if ((int)string.charAt(i) != 32 ){

string += (int)string.charAt(i);

      }

mas n deu....alguem sabe como é k indico o char espaço??

Link to comment
Share on other sites

freesumo thx pelo código era algo do género que eu precisava, infelizmente n vim a tempo pa ve-lo pa por no meu trabalho mas eu consegui fazer de outra maneira

fiz:

String string = string.trim();

string = string.charAt(0) + string.substring(1).trim();

e assim consegui eliminar tds os espaços , mas isto funciona para o meu prob em especifico, para futuro o codigo k mandas t é bm melhor mt obrigado

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.