How to change string case in NIM? - nim-lang

In NIM 0.17 toLower is deprecated.
So, what would be the proper way of changing the case of a string in NIM?

strutils.toLowerAscii or unicode.toLower depending on which you want.

Related

Using regex and its flags with .eq() function in python to ignore case

I've checked the docs (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.eq.html)
I'm thinking something like below where I can use and re.I to ingnore case or use any other flag for that matter.
df.column.eq('Male').sum()
You can use the Series.str.contains function with case=False argument, ^Male$ as regex pattern and the regex=True argument:
df['column'].str.contains('^Male$', case=False, regex=True).sum()
See the Series.str.contains documentation.
Also, see What do ^ and $ mean in a regular expression?

Regex or IndexOf?

I have a long string "AB100123485;AB10064279293-IP-1-KNPO;AB473898487-MM41". I have to extract integer value after "IP-" i.e 1 (only) what is the most efficient way ? I am using c#
Thanks
The 'most-efficient' way depends on how consistent your string is in terms of length and appearance. You can surely do this with a regular expression as a quick solution if you just want to get the digit directly following IP-.
You can utilize the RegularExpressions API, passing in your regular expression and input string.
https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.match?view=netframework-4.8#System_Text_RegularExpressions_Regex_Match_System_String_System_String_
This pattern should get you started IP-[0-9]; refine it more to your use case as needed.
For example:
Match matched = System.Text.RegularExpressions.Match(
"AB100123485;AB10064279293-IP-1-KNPO;AB473898487-MM41",
"IP-[0-9]"
);

change case from odd/even argument

how should I define a function that takes in a string and returns the string in upper and lowercases according to even and odd indexing?
def myfunc(string):
for some in string:
if string.index%2==0:
I have written this much but I do not know what should I type now.
please help.
Here you can find the string methods Specially look at upper() and lower() which will be your friend here.

Identifying String format for a Color string

given a string, I need to test if the string is in the following format [000,000,000,000] where 0 represents any number. However each of the 4 numbers could be 1,2 or 3 digits. If an error is detected, I need to throw a NumberFormatException and convert it to a FormatException. Thanks.
The easiest way would be to check if it matches a regular expression. Something like this would do the trick:
\[[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3}\]
or this if you want a condensed version:
\[([0-9]{1,3},){3}[0-9]{1,3}\]
You didn't specify a language (I'd guess it's Java?), but they all have some regex functionality. Throwing the exception should be pretty simple for you, so I won't go into that...

Is VB6 string comparison case insensitive?

if strValue = 'Hello' then what would be the value of (strValue <> 'HELLO') be?
It depends on how you use the Option Compare statement. It can work either way.
Option Compare Text 'Case insensitive'
Option Compare Binary 'Case sensitive (default)'
Here's a VB6 string tutorial.
No, it's case sensitive (by default at least though you'll want to check - if Option Compare is set to Binary or not set then it's case sensitive, if it's set to text then it's case insensitive).
Lcase() both sides if you'd rather it were case insensitive.
The reason I prefer this to changing / setting option compare is that someone looking at the code doesn't have to go hunting to see what option compare is set to to understand how it's going to behave BUT it's almost certainly slower (not significantly unless you're calling it repeatedly) and some might see it as not particularly neat.
The documentation is fairly clear
If you use Option Compare Text in the Declarations section of a
module [the top of the file], string comparisons aren't case-sensitive.
If you use Option Compare Binary, comparisons are case-sensitive.
If you use Option Compare Database [only valid in Access VBA], the comparison method is set by the current database.

Resources