如何删除多个和,或 [英] how to remove multiple and,or

查看:98
本文介绍了如何删除多个和,或的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 如果我的搜索字符串包含多个and,multiple或

我们正在替换和,或使用空格.


例如:-搜索字符串,例如"andandandandjavaandandand".
我们将全部删除.(然后搜索字符串为"java".

and和and和and和and java或or或orororor.此处也用空格替换所有and.或
.
到此为止一切正常.

但是问题是我的搜索词是否像"android"
那我就不想删除和"

如果像"configurator".在此我不想删除,或者.因为它是一个有意义的单词.我想搜索该单词.


这是我的代码

 如果(TextBox1.Text.EndsWith(" ))
                {
                    TextBox1.Text = TextBox1.Text.Substring( 0 ,TextBox1.Text.Length- 3 );
                    TextBox1.Text.Trim();
                }
                如果(TextBox1.Text.EndsWith(" ))
                {
                    TextBox1.Text = TextBox1.Text.Substring( 0 ,TextBox1.Text.Length- 2 );
                    TextBox1.Text.TrimEnd();
                }
                如果(TextBox1.Text.StartsWith(" ))
                {
                    TextBox1.Text = TextBox1.Text.Remove( 0  3 );
                }
                如果(TextBox1.Text.StartsWith(" ))
                {
                    TextBox1.Text = TextBox1.Text.Remove( 0  2 );
                }



如何为 =" 解决方案

尝试一下...

if(TextBox1.Text.EndsWith(和")|| TextBox1.Text.EndsWith(和")|| TextBox1.Text.EndsWith("andand"))
{
TextBox1.Text = TextBox1.Text.Substring(0,TextBox1.Text.Length-3);
TextBox1.Text.Trim();
}
如果(TextBox1.Text.EndsWith(或")|| TextBox1.Text.EndsWith(或")|| TextBox1.Text.EndsWith("or"))
{
TextBox1.Text = TextBox1.Text.Substring(0,TextBox1.Text.Length-2);
TextBox1.Text.TrimEnd();
}
如果(TextBox1.Text.StartsWith(和")|| TextBox1.Text.StartsWith(和")|| TextBox1.Text.StartsWith(和"))
{
TextBox1.Text = TextBox1.Text.Remove(0,3);
}
如果(TextBox1.Text.StartsWith(或")|| TextBox1.Text.StartsWith(或")|| TextBox1.Text.StartsWith(或"))
{
TextBox1.Text = TextBox1.Text.Remove(0,2);
}


hi if my search string contains multiple and,multiple or

we are replacing and,or with space.


for example:- search string like "andandandandjavaandandand".
we are removing all and.(then search string is "java".
OR
and and and and and and java or or or orororor.here also replacing all and,or with space.

upto this it is working fine.

But the problem is if my search word is like "android"
then i don''t want to remove "and"

if like "configurator".in this i don''t want to remove or.because it is a meaningful word.i want to search on that word.


this is my code

if (TextBox1.Text.EndsWith("and"))
                {
                    TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 3);
                    TextBox1.Text.Trim();
                }
                if (TextBox1.Text.EndsWith("or"))
                {
                    TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 2);
                    TextBox1.Text.TrimEnd();
                }
                if (TextBox1.Text.StartsWith("and"))
                {
                    TextBox1.Text = TextBox1.Text.Remove(0, 3);
                }
                if (TextBox1.Text.StartsWith("or"))
                {
                    TextBox1.Text = TextBox1.Text.Remove(0, 2);
                }



how can i write code for this

解决方案

try this...

if (TextBox1.Text.EndsWith(" and") || TextBox1.Text.EndsWith("and ") || TextBox1.Text.EndsWith("andand"))
{
TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 3);
TextBox1.Text.Trim();
}
if (TextBox1.Text.EndsWith(" or") || TextBox1.Text.EndsWith("or ") || TextBox1.Text.EndsWith("oror"))
{
TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 2);
TextBox1.Text.TrimEnd();
}
if (TextBox1.Text.StartsWith("and") || TextBox1.Text.StartsWith("and ") || TextBox1.Text.StartsWith("andand"))
{
TextBox1.Text = TextBox1.Text.Remove(0, 3);
}
if (TextBox1.Text.StartsWith("or") || TextBox1.Text.StartsWith("or ") || TextBox1.Text.StartsWith("oror"))
{
TextBox1.Text = TextBox1.Text.Remove(0, 2);
}


这篇关于如何删除多个和,或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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