How do I replace a string with case insensitive search? - vb.net

In VB6, I could say:
s = Replace(s, "Find", "Replace", vbTextCompare)
In VB.NET, there is only String.Replace(uFind, uReplace) which would mean binary compare, I guess.
Is there no .NET version that would provide the usual CultureInvariantIgnoreDayTimeAndHowEmptyMyStomachIs and similar search option?

Related

How do I concatenate Strings in Kotlin?

Obviously there are multiple ways to concatenate Strings in Kotlin:
processString(pojo.name + " " + pojo.value)
processString("${pojo.name} ${pojo.value}")
processString(pojo.name.plus(" ").plus(pojo.value))
Of course also with StringBuilder, concat()-Method etc.
Those will work.
But my question is, why is Android Studio proposing "convert concatenation to template" and converts 1. to 2. ? Are there any speed advantages with 2.? So wahts the advantage using 2.?
TL;DR: String Templates are the most idiomatic way to concatenate strings
The documentation states
Note that in most cases using string templates or raw strings is preferable to string concatenation.
String templates are basically the same as regular concatenation (using +) but more compact, idiomatic and equally efficient. Both variants are implemented using StringBuilders in the byte code.
That's because the 1. approach comes from java. Of course the compiler knows what's happening but the suggestion is to use it in Kotlin like the 2. point is stated. Using the 2. approach is better because you might get confused with the + (plus()) operator that is used to sum up numbers.

LIKE operator in XQL

I am doing some XML parsing in webMethods which only supports XQL, not XPath/XQuery.
I'm trying to find the LIKE operator to do a wildcard search on an attribute value
/MAP[#MODE='INPUT']/MAPSET[#FIELD LIKE '/documentTypeName*']/DATA/Values/value
In XQuery, I was using the matches() function. Have been surprised at my lack of finding an answer through searching. My best bet was http://www.ibiblio.org/xql/xql-proposal.html which says it should be keyword contains but this doesn't seem correct.
Pretty much a necro, but i believe you are looking for 'icontains'.
http://www.ibiblio.org/xql/xql-proposal.html#Comparisons
Section 1.4.3 Comparisons. This should be a case insensitive version of 'contains'
(field icontains "/documentTypeName*")

Sqlite "word only" search

I want to implement a "word only" search in sqlite.
My first option seems to be [charlist] that select words that are surrounded by [space, tab, point, comma, punctuation, etc].
Something like this: SELECT ... WHERE 'name' LIKE "%[ \t.,!?]word[ \t.,!?]%"
However I cannot find a way to add space/tab to [charlist].
Is this possible ?
What is "the best way" to implement a "word only" search in sql ?
Like does not support character classes, but GLOB does.
However, searching for words is what the full-text search extension has been designed for.

What do numbers in braces e.g. "{0}" mean?

I've been looking around but having great difficulty finding the answer to this question as the thing I'm looking for is so unspecific.
I've seen a lot of code which uses {0} in it, and I still can't work out what it's doing. Here's an example:
Dim literal As String = "CatDogFence"
Dim substring As String = literal.Substring(6)
Console.WriteLine("Substring: {0}", substring)
Console.WriteLine("Substring: {0}", substring)
Is the same as
Console.WriteLine("Substring: " & substring)
When using Console.WriteLine, {n} will insert the nth argument into the string, then write it.
A more complex example can be seen here:
Console.WriteLine("{0} {1}{2}", "Stack", "Over", "flow")
It will print Stack Overflow.
Console.WriteLine() and String.Format() use that syntax.
It allows you to inject a variable into a string, for example:
dim name = "james"
String.Format("Hello {0}", name)
That string will be "Hello james"
Using Console.Writeline:
Console.WriteLine("Hello {0}",name)
That will write "Hello james"
It's a placeholder. Beginning at the second parameter (substring in your case), they are included in the given string in the given order. This way you avoid long string concatenations using + operator and can do easier language localization, because you can pull the compete string including the placeholders to some external resource file etc.
It is called composite formatting and is supported by many methods, Console.WriteLine being one. Besides indexed placeholders there are other features available. Here is a link to the documentation that shows some of the other features of composite formatting.
Composite Formatting

VB.Net String comparison and Wildcard values

Is it possible to do String comparison where one of the strings I am comparing against has wild cards and is generally just for formatting purposes. For example
Dim correctFormat as String = "##-##-###-##"
Dim stringToCheck = someClass.SomeFunctionThatReturnsAStringToCheck
If FormatOf(CorrectFormat) = FormatOF(StringToCheck) then
Else
End if
I am aware of the made up FormatOf syntax, but I'm just using it to show what I am asking.
No need for regular expressions.
You can simply use the Like operator, which supports ?, * and # as wildcards and also character lists ([...], [!...])
So you simply change your code to:
If stringToCheck Like correctFormat Then
and it will work as expected.
The way is to use regular expressions - that's what they are for.
This is the regular expression that matches the format you have posted:
^\d{2}-\d{2}-\d{3}-\d{2}$
As the previous post mentioned, you should use regular expressions for that purpose - they are way better for that task.
Sadly, learning them can be confusing, especially finding bugs can be really annoying.
I really like http://www.regular-expressions.info/ and http://regexpal.com/ for building and testing regexes before.
In VB.net use something like reg.ismatch