Determine if char is a num or letter

You’ll want to use the isalpha() and isdigit() standard functions in <ctype.h>. char c=”a”; // or whatever if (isalpha(c)) { puts(“it’s a letter”); } else if (isdigit(c)) { puts(“it’s a digit”); } else { puts(“something else?”); }

How to remove all non-alpha numeric characters from a string in MySQL?

Using MySQL 8.0 or higher Courtesy of michal.jakubeczy’s answer below, replacing by Regex is now supported by MySQL: UPDATE {table} SET {column} = REGEXP_REPLACE({column}, ‘[^0-9a-zA-Z ]’, ”) Using MySQL 5.7 or lower Regex isn’t supported here. I had to create my own function called alphanum which stripped the chars for me: DROP FUNCTION IF EXISTS … Read more

How do I sort strings alphabetically while accounting for value when a string is numeric?

Pass a custom comparer into OrderBy. Enumerable.OrderBy will let you specify any comparer you like. This is one way to do that: void Main() { string[] things = new string[] { “paul”, “bob”, “lauren”, “007”, “90”, “101”}; foreach (var thing in things.OrderBy(x => x, new SemiNumericComparer())) { Console.WriteLine(thing); } } public class SemiNumericComparer: IComparer<string> { … Read more

How do I block or restrict special characters from input fields with jquery?

A simple example using a regular expression which you could change to allow/disallow whatever you like. $(‘input’).on(‘keypress’, function (event) { var regex = new RegExp(“^[a-zA-Z0-9]+$”); var key = String.fromCharCode(!event.charCode ? event.which : event.charCode); if (!regex.test(key)) { event.preventDefault(); return false; } });

How to generate a random alpha-numeric string

Algorithm To generate a random string, concatenate characters drawn randomly from the set of acceptable symbols until the string reaches the desired length. Implementation Here’s some fairly simple and very flexible code for generating random identifiers. Read the information that follows for important application notes. public class RandomString { /** * Generate a random string. … Read more

How to strip all non-alphabetic characters from string in SQL Server?

Try this function: Create Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000)) Returns VarChar(1000) AS Begin Declare @KeepValues as varchar(50) Set @KeepValues=”%[^a-z]%” While PatIndex(@KeepValues, @Temp) > 0 Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, ”) Return @Temp End Call it like this: Select dbo.RemoveNonAlphaCharacters(‘abc1234def5678ghi90jkl’) Once you understand the code, you should see that it is relatively simple to change it … Read more