Advertisement
Guest User

withoutSpaces

a guest
Jul 14th, 2020
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.33 KB | None | 0 0
  1. fun EditText.withoutFirstSpaces (): String {
  2.  
  3.     var result = ""
  4.     val length = text.length
  5.     var spaceAllowed = false
  6.  
  7.     for (i in 0 until length) {
  8.         if (text[i] != ' ' || spaceAllowed) {
  9.             result += text[i]
  10.             spaceAllowed = true
  11.         }
  12.     }
  13.  
  14.     this.setText(result)
  15.  
  16.     return result
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement