c# - 使用剪贴板选择句子的一部分而不是整个句子
问题描述
我想要我的程序而不是选择整个句子进行返回,如果复制它,部分句子也是可能的。
这是我的代码:
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
//check if current operation is a clipboard
if (m.Msg == WM_DRAWCLIPBOARD)
{
//then we use a try catch block so if
//anything wrong happens in Clipboard.GetText() our program wont crash
try
{
//with foreach we go through all our questions
foreach (string question in questionList)
{
//and we check if clapboarded text is matches with our question
if (Clipboard.GetText() == "When a computer is being assembled, which action can be taken to help eliminate cable clutter within a computer case?")
{
notifyIcon1.Icon = SystemIcons.Exclamation;
notifyIcon1.BalloonTipTitle = "When a computer is being assembled, which action can be taken to help eliminate cable clutter within a computer case?";
notifyIcon1.BalloonTipText = "Install a modular power supply.*";
notifyIcon2.BalloonTipIcon = ToolTipIcon.Error;
notifyIcon1.ShowBalloonTip(100);
return;
}
这就是问题:“在组装计算机时,可以采取哪些措施来帮助消除计算机机箱内的电缆杂乱?”
例如,如果您复制了以下内容,我想:当组装计算机时,
你得到相同的匹配和相同的通知
提前致谢
解决方案
使用字符串方法 .Contains() 而不是相等比较。
if (Clipboard.GetText().Contains(yourString))
推荐阅读
- rest - 在 vuejs 中处理来自 restful api 的上下文链接
- python - Retrieve file from mongoDB using python
- python - Kivy module in python
- java - 更改列表视图项的颜色
- git - Git inflate returned -3
- java - 使用阿里巴巴fastjson反序列化Java类
- android - POSTMAN 工作,但 android okhttp 请求响应不同的值
- python - 根据 Group By 列执行计算,然后我必须将该值传递给数据框中的新列
- gitlab - .gitlab-ci.yml 覆盖在 appsetings.json 中定义的变量
- python - 计算每个标点符号