QuickTheories icon indicating copy to clipboard operation
QuickTheories copied to clipboard

Creating numeric strings of specified lengths

Open ZmurLV opened this issue 6 years ago • 1 comments

Needed to create strings like this: "ISO0260000590230322000012A800001" that is a constant "ISO" + 22 numeric characters + A + 6 numeric characters. Could not generate a numeric string of fixed length, because strings().numeric() doesn't seem to allow to set the length of a result.

ZmurLV avatar Jan 24 '20 20:01 ZmurLV

It's possible to achieve this result.

new StringsDSL().betweenCodePoints((int) '0', (int)'9').ofLengthBetween(22, 22); 

or

new StringsDSL().betweenCodePoints(48, 57).ofLengthBetween(22, 22); 

depending on personal preferences.

A dedicated API for this might also be nice.

hyperpape avatar May 18 '20 02:05 hyperpape