简体   繁体   中英

Delete a character from string realbasic

I have a virtual keyboard created in RealBasic. When I press letters, numbers I append it to a textfield all its ok but, how do I delete characters from that textfield from current cursor position when I press "Delete" button from virtual keyboard?

To append letters or numbers to the textfields I use:

TextField1.Text = TextField1.text + me.Caption //to append caption
TextField1.SelStart = Len(TextField1.text)  // to move cursor at the end of string

Paul's solution works if you only plan to delete the last typed character.

But beware: If you let the user also move the cursor left and right, you have to delete the text at the position of the cursor, of course. And if you also allow the user to select text, then it's even more complicated.

I suggest that your virtual keyboard simply send the typed key to the system as if the user had pressed the key. That way, the TextEdit field will do everything for you.

To make this work, however, you need custom solutions for each OS platform you want to support.

Let me know which platforms you plan to support and I'll see what I can find. I have some code for OSX but not for Windows, yet.

Doing what Thomas said means:

dim n as String = TextField1.Text
n = newText.left(TextField1.selStart) + n.right(n.len - textField1.selStart - 1)
textField1.text = n

刚刚丢掉最后一个角色:

TextField1.Text = TextField1.Text.Left(TextField1.Len-1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM