我正在尝试将一个被调用的字符串facility与多个可能的字符串进行比较来测试它是否有效.有效字符串是:
auth, authpriv, daemon, cron, ftp, lpr, kern, mail, news, syslog, user, uucp, local0, ... , local7
Run Code Online (Sandbox Code Playgroud)
有没有一种有效的方法来做到这一点:
if facility == "auth" or facility == "authpriv" ...
Run Code Online (Sandbox Code Playgroud) 我想比较其中有两个非英文字符的字符串
String1 = debarquer
String2 = débárquér
Run Code Online (Sandbox Code Playgroud)
在比较上面两个字符串时,他们应该说相等.
我正在寻找一个允许两个字符串进行智能比较的库/类.最好它会给出两个字符串相似的百分比.我正在比较公司名称,在不同存储库中记录的地址,因此在名称中有许多拼写错误或不一致.
要比较的示例字符串:
"Good Company Ltd." vs. "GoodCompany"
"Baker Street 2" vs. "Baker Str. 2"
Run Code Online (Sandbox Code Playgroud)
如果我得到相似百分比的结果,那么这可以是这种数据的智能合并的输入.
你知道任何能够进行这种智能字符串比较的好库吗?
这是我多年来不时尝试过的,而且从未成功过.我只想根据字符串相等性为Visual C++ 2012设置条件断点.我想测试的变量是
string test;
Run Code Online (Sandbox Code Playgroud)
我试过了
test == "foo"
=> The breakpoint cannot be set. no operator "==" matches these operands
test == string("foo")
=> The breakpoint cannot be set. no operator "==" matches these operands
test.compare("foo") == 0
=> The breakpoint cannot be set. This expression has side effects and will not be evaluated.
strcmp(test.c_str(), "foo") == 0
=> The breakpoint cannot be set. This expression has side effects and will not be evaluated.
Run Code Online (Sandbox Code Playgroud) c++ breakpoints string-comparison conditional-breakpoint visual-studio-2012
我有一个数据库,在标签系统中使用了很多单词.我已经为自动完成框创建了必要的代码,但我不确定如何以最有效的方式从数据库中获取匹配的条目.
我知道LIKE命令,但在我看来它更像是一个EQUAL命令.我只得到与我输入的单词完全相同的单词.
我的计划是读取每一行,然后使用C#的string.StartsWith()和string.Contains()函数来查找可能适合的单词,但我认为对于大型数据库,读取每一行可能效率低下然后过滤它们.
有没有办法只读取以SQL Server开头或包含给定字符串的行?
如何在执行比较之前将字符串转换为大写,或者是否可以通过忽略大小写来比较字符串
if (Convert.ToString(txt_SecAns.Text.Trim()).ToUpper() ==
Convert.ToString(hidden_secans.Value).ToUpper())
Run Code Online (Sandbox Code Playgroud) 我正在开发一个C#4.5应用程序,我需要一个函数来返回true以进行以下比较:
"blaLéOnArd/ o bla".ComplexContains("leonardo")
换句话说,我string.Compare(str1, str2, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace)还需要检查"包含!
有人可以帮忙吗?
假设我有两个字符串:a和b.为了比较a和被忽略大小写时是否具有相同的值,我总是使用:
// (Assume a and b have been verified not to be null)
if (a.ToLower() == b.ToLower())
Run Code Online (Sandbox Code Playgroud)
但是,使用Reflector,我在.NET Framework中已经看过几次:
// (arg three is ignoreCase)
if (string.Compare(a, b, true) == 0)
Run Code Online (Sandbox Code Playgroud)
我测试哪个更快,每次用我使用的字符串ToLower()节拍Compare().
是否有理由Compare()而不是ToLower()?有什么不同的CultureInfo?我在挠头.
我想做这样的事情:
declare @temp as varchar
set @temp='Measure'
if(@temp == 'Measure')
Select Measure from Measuretable
else
Select OtherMeasure from Measuretable
Run Code Online (Sandbox Code Playgroud) 我在mac上使用eclipse IDE(版本:3.4.2),我遇到了以下问题.
当使用equal()或equalsIgnoreCase()方法比较字符串时,即使字符串相等,我也会收到false.例如,下面的代码将以下条件视为false,即使值[0] ="debug_mode"
if (values[0].equalsIgnoreCase("debug_mode"))
debug_mode = true;
Run Code Online (Sandbox Code Playgroud)
这是以下循环的一部分:
String value = dis.readLine();
String values[] = value.trim().split("=");
if (values.length >= 2)
{
Config.prnt_dbg_msg(values[0] + "\t" + values[1]);
if (values[0].equalsIgnoreCase("debug_mode"))
debug_mode = isTrue(values[1]);
if (values[0].equalsIgnoreCase("debug_query_parsing"))
debug_query_parsing = isTrue(values[1]);
if (values[0].equalsIgnoreCase("username"))
Connection_Manager.alterAccessParameters(values[1], null, null);
if (values[0].equalsIgnoreCase("password"))
Connection_Manager.alterAccessParameters(null, values[1], null);
if (values[0].equalsIgnoreCase("database"))
Connection_Manager.alterAccessParameters(null, null, values[1]);
if (values[0].equalsIgnoreCase("allow_duplicate_entries"))
allow_duplicate_entries = isTrue(values[1]);
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用value[0].equal("debug_mode")并得到了相同的结果.有人知道为什么吗?