How to Identify Characters

0

I have a class that takes a String and looks at the first character and if the character is empty ("") it returns me the first letter.

public String textReturn(String x){
   int v1 = 0,v2 = 1;
   String a =" ";

   while(true){

      if( x.substring(v1,v2).equal(" ")){

         a =  x.substring(v1,v2);
         break;
      }else{
         v1++;
         v2++;
      }
   }

  return a;
}

But this text comes from an EditText and if in it I give an enter account as if it were a character, I wanted to know how to skip the line break or if it is also a character type String a.equal (b /)

    
asked by anonymous 23.02.2018 / 15:22

1 answer

0

Why not use the "TrimStart (new char [] {'', '\ n'})" method and validate if the returned string is equal to the original if it does not return the first letter? If what you want is to return the first letter when it finds space is returning space and also, as is the method, if there is no space at the beginning of the text infinite loop occurs, and if the variables V1 and V2 are always the same for not using just one?

    
23.02.2018 / 15:52