How do I get a consistent byte representation of strings in C# without manually specifying an encoding?

Contrary to the answers here, you DON’T need to worry about encoding if the bytes don’t need to be interpreted! Like you mentioned, your goal is, simply, to “get what bytes the string has been stored in”. (And, of course, to be able to re-construct the string from the bytes.) For those goals, I honestly … Read more

Generate random string/characters in JavaScript

I think this will work for you: function makeid(length) { var result=””; var characters=”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } console.log(makeid(5));

Extract filename and extension in Bash

First, get file name without the path: filename=$(basename — “$fullfile”) extension=”${filename##*.}” filename=”${filename%.*}” Alternatively, you can focus on the last “https://stackoverflow.com/” of the path instead of the ‘.’ which should work even if you have unpredictable file extensions: filename=”${fullfile##*/}” You may want to check the documentation : On the web at section “3.5.3 Shell Parameter Expansion” … Read more

How do I check if a string contains a specific word?

Now with PHP 8 you can do this using str_contains: if (str_contains(‘How are you’, ‘are’)) { echo ‘true’; } RFC Before PHP 8 You can use the strpos() function which is used to find the occurrence of one string inside another one: $a=”How are you?”; if (strpos($a, ‘are’) !== false) { echo ‘true’; } Note … Read more

Creating multiline strings in JavaScript

Update: ECMAScript 6 (ES6) introduces a new type of literal, namely template literals. They have many features, variable interpolation among others, but most importantly for this question, they can be multiline. A template literal is delimited by backticks: var html = ` <div> <span>Some HTML here</span> </div> `; (Note: I’m not advocating to use HTML … Read more

Case insensitive ‘Contains(string)’

You could use the String.IndexOf Method and pass StringComparison.OrdinalIgnoreCase as the type of search to use: string title = “STRING”; bool contains = title.IndexOf(“string”, StringComparison.OrdinalIgnoreCase) >= 0; Even better is defining a new extension method for string: public static class StringExtensions { public static bool Contains(this string source, string toCheck, StringComparison comp) { return source?.IndexOf(toCheck, … Read more

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