How to Identify Carcter

Asked

Viewed 172 times

0

I have a class who catches a String and look 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 a Edittext and if in it I give an account as if it were a character, I wonder how do I get to skip the line break or if it is also a character like String a.Equal(b/)

  • Normally Edittext members have a "text" property that already returns the text without special characters. You could use something like: textReturn( editText.text). But your question is not very clear I may not have understood the real problem

  • this my method takes any text and checks if the first character is empty ('" "), if it is empty it looks at the second otherwise it returns me the character... it works, but if I give an entity it breaks the line and when he looks at the first character will not ta empty because he considers the line break a character... wanted to know what is the symbol of the line break to compare or how to skip the line break and go to the next character.

  • How do you pass the text of Edit to him? I don’t understand how "Enter" is going inside the string, not taking the "pure" text of Edit?

  • i call the textReturn(edittext.gettext) method and then my method checks the characters. but if in Edittext I hit Enter it considers line breaking a character

  • type so the method looks at the characters and skips the empty characters and shows me on the screen the first letter, using Toast, .. this work, I can give as much space as I want it to skip the spaces and return me the first letter, but when I press Enter it returns me in empty Toast

1 answer

0

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

  • the variables are different and this be inside a Try catch if the loop does not lock

  • I just wanted it the same way it looks if the character and empty also wanted it to look if it was a line break

  • 1

    \n = line break

Browser other questions tagged

You are not signed in. Login or sign up in order to post.