Case insensitive ‘Contains(string)’

To test if the string paragraph contains the string word (thanks @QuarterMeister) Where culture is the instance of CultureInfo describing the language that the text is written in. This solution is transparent about the definition of case-insensitivity, which is language dependent. For example, the English language uses the characters I and i for the upper and lower case versions of the ninth letter, whereas the Turkish language uses … Read more

error: switch quantity not an integer

In switch, the expression must be of “an integral type or of a class type for which there is an unambiguous conversion to integral type” (quoting VS2008 docs). A string class doesn’t have “unambiguous conversion to integral type”, like a char does. As a work-around: Create a map<string, int> and switch on the value of the map: switch(command_map[command]) ` Do a set of if/else instead of … Read more

How to convert string to boolean php

Strings always evaluate to boolean true unless they have a value that’s considered “empty” by PHP (taken from the documentation for empty): “” (an empty string); “0” (0 as a string) If you need to set a boolean based on the text value of a string, then you’ll need to check for the presence or otherwise of that value. … Read more

How do you allow spaces to be entered using scanf?

People (and especially beginners) should never use scanf(“%s”) or gets() or any other functions that do not have buffer overflow protection, unless you know for certain that the input will always be of a specific format (and perhaps not even then). Remember than scanf stands for “scan formatted” and there’s precious little less formatted than user-entered data. It’s ideal if you have total control of … Read more

Proper way to empty a C-String

It depends on what you mean by “empty”. If you just want a zero-length string, then your example will work. This will also work: If you want to zero the entire contents of the string, you can do it this way: but this will only work for zeroing up to the first NULL character. If … Read more

PHP to write Tab Characters inside a file?

The tab character is \t. Notice the use of ” instead of ‘. PHP Strings – Double quoted If the string is enclosed in double-quotes (“), PHP will interpret more escape sequences for special characters: … \t horizontal tab (HT or 0x09 (9) in ASCII) Also, let me recommend the fputcsv() function which is for the purpose of writing CSV files.

Java String to SHA1

UPDATEYou can use Apache Commons Codec (version 1.7+) to do this job for you. DigestUtils.sha1Hex(stringToConvertToSHexRepresentation) Thanks to @Jon Onstott for this suggestion. Old AnswerConvert your Byte Array to Hex String. Real’s How To tells you how. and (copied from Real’s How To) BTW, you may get more compact representation using Base64. Apache Commons Codec API 1.4, has this nice utility … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)