[解决]检查字符串之间的空白 [英] [Solved] checking whitespace between strings

查看:70
本文介绍了[解决]检查字符串之间的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a RichTextBox and a listbox. If a User Typed One string and hit space bar then again typed on string and if user hit alt+space(which is shortcut to display listview, to show filter data of second string). My Problem is, Ihave take the string after space and match that with my listbox and show suggesition to the user





i am using using:



i am using :

SelectExactMatch(richTextBox1.Text);




public void SelectExactMatch(string find)
        {
            listBox1.SelectedIndex = listBox1.FindString(find);
        }





此代码在列表框中搜索字符串...但问题是richtextbox1.text表示所有文本

i只想把用户点击alt +空格的字符串带到近一个...







请给我一些建议或提示...



this code to search string in listbox... but problem is richtextbox1.text means all the the text
i just want to take that string that user hit alt+space to the near one...



pls give me some suggestion or hint...

推荐答案

你可以使用 Split()方法。



查看以下链接 [ ^ ]。



链接示例;



You can use Split() method.

Have a look at the following link[^].

An example from the link;

string s = "there is a cat";
//
// Split string on spaces.
// ... This will separate all the words.
//
string[] words = s.Split(' ');
foreach (string word in words)
{
    Console.WriteLine(word);
}





所以在这种情况下,第二个单词是是=>你可以在单词中找到它[1]



适应你的代码:



so in this case second word which is "is"=> you can find it in words[1]

Adaptation to your code:

SelectExactMatch(words[1]);



祝你好运,

OI


Good luck,
OI


这篇关于[解决]检查字符串之间的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆