Sorting strings with numbers in Bash [duplicate]
Execute this sort -t _ -k 2 -g data.file -t separator -k key/column -g general numeric sort
Execute this sort -t _ -k 2 -g data.file -t separator -k key/column -g general numeric sort
Using Apache Commons Lang: !StringUtils.isAlphanumeric(String) Alternativly iterate over String’s characters and check with: !Character.isLetterOrDigit(char) You’ve still one problem left: Your example string “abcdefà” is alphanumeric, since à is a letter. But I think you want it to be considered non-alphanumeric, right?! So you may want to use regular expression instead: String s = “abcdefà”; Pattern … Read more
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
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; } });
Be aware, that \W leaves the underscore. A short equivalent for [^a-zA-Z0-9] would be [\W_] text.replace(/[\W_]+/g,” “); \W is the negation of shorthand \w for [A-Za-z0-9_] word characters (including the underscore) Example at regex101.com
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
Regex is the best tool for the job; what it should be depends on the problem specification. The following removes leading zeroes, but leaves one if necessary (i.e. it wouldn’t just turn “0” to a blank string). s.replaceFirst(“^0+(?!$)”, “”) The ^ anchor will make sure that the 0+ being matched is at the beginning of … Read more
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