Complex “Contains” string comparison

You could use an appropriate CompareInfo and then CompareInfo.IndexOf(string, string, CompareOptions) and check the result against -1. Sample: using System; using System.Globalization; class Program { static void Main() { var compareInfo = CultureInfo.InvariantCulture.CompareInfo; var options = CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace; var haystack = “bla Lé OnAr d/o bla”; var needle = “leonardo”; var index … Read more

how to compare two strings in javascript if condition

You could check every option. if (compare === “page1” || compare === “page2”) { Or you could use an array and check with an existential quantifier like Array#some against, like if ([“page1”, “page2”].some(a => a === compare)) { var compare = “page3”; if (compare === “page1” || compare === “page2”) { document.body.innerHTML = “github url”; … Read more

strcmp or string::compare?

For C++, use std::string and compare using string::compare. For C use strcmp. If your (i meant your programs) strings (for some weird reason) aren’t nul terminated, use strncmp instead. But why would someone not use something as simple as == for std::string ?

Check if variable starts with ‘http’

if (strpos($source, ‘http’) === 0) { $source = “<a href=\”$source\”>$source</a>”; } Note I use ===, not == because strpos returns boolean false if the string does not contain the match. Zero is falsey in PHP, so a strict equality check is necessary to remove ambiguity. Reference: http://php.net/strpos http://php.net/operators.comparison

how to compare list elements(type string) and string(in request scope) using struts 2 tags

With the IteratorStatus object: <s:iterator value=”lis” status=”ctr”> <s:property /> <s:if test=”%{#request.str.equals(lis[#ctr.index])}”> -> This value from “lis” is equal to the value of “str” </s:if> <br/> </s:iterator> With the var parameter: <s:iterator value=”lis” var=”currentValue”> <s:property /> <s:if test=”%{#request.str.equals(#currentValue)}”> -> This value from “lis” is equal to the value of “str” </s:if> <br/> </s:iterator> With the top … Read more