Keep only numeric value from a string?

You do any of the following: Use regular expressions. You can use a regular expression with either A negative character class that defines the characters that are what you don’t want (those characters other than decimal digits): private static readonly Regex rxNonDigits = new Regex( @”[^\d]+”); In which case, you can do take either of … Read more

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

Counting palindromic substrings in O(n)

The following site shows an algorithm for computing the longest palindromic substring in O(n) time, and does so by computing the longest palindromic substring at every possible center and then taking the maximum. So, you should be able to easily modify it for your purposes. http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ EDIT: The first link looks a little shaky upon … Read more

Groovy: How can I include backslashes inside a string without escaping?

Wow, another gotcha with putting Windows files paths in slashy strings. Nice catch. The gotcha I’ve encountered before was including a trailing backslash on the path, e.g. /C:\path\/, which results in an unexpected char: 0xFFFF error. Anyways, for the sake of an answer, given that Windows paths are case insensitive, why not exploit it for … Read more

tech