我遇到了这样一种情况,我实际上无法前进:我有一个输入字段,在该字段中我应该识别出用户通过cmd+v
粘贴数据,因为我有一个填入代码
public InputField _wordsEntry;
if ( (Input.GetKey(KeyCode.RightCommand) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.V) || Input.GetMouseButtonUp(1))
{
if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.name == "WordsEntry")
{
if (string.IsNullOrEmpty(_wordsEntry.text))
_wordsEntry.text =ClipboardHelper.Clipboard;
else
_wordsEntry.text = _wordsEntry.text + '\n' + ClipboardHelper.Clipboard;
_wordsEntry.MoveTextEnd(false);
}
}
问题是if (string.IsNullOrEmpty(_wordsEntry.text))
,这种情况总是变得不正确。当我尝试将复制的内容粘贴到else
条件时,是否缺少任何内容?
答案 0 :(得分:1)
实际上我很确定这就是答案,所以我将评论转换为xd
像这样尝试:
groovy:000> a = "hello there Moi"
groovy:000> p = java.util.regex.Pattern.compile("(?<=there\\s)\\w+")
groovy:000> m = p.matcher(a)
groovy:000> m.replaceAll("John")
===> hello there John
或类似这样:
(?<=there\\s)\\w+