简体   繁体   English

从字符串realbasic中删除一个字符

[英]Delete a character from string realbasic

I have a virtual keyboard created in RealBasic. 我有一个在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. 如果您只打算删除最后输入的字符,Paul的解决方案就有效。

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. 这样,TextEdit字段将为您完成所有事情。

To make this work, however, you need custom solutions for each OS platform you want to support. 但是,要使其工作,您需要为要支持的每个OS平台提供自定义解决方案。

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. 我有一些OSX代码,但不适用于Windows。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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