As I continue to work through the HTML objects I am incorporating into a project, I found I was repeatedly writing variants of a code block to step through a string to analyze its makeup. I finally got smart and exported the routine to a callable module, which I am adding here. I have already added one additional statistic to the code, and it would be easy to add more, so this is a routine that can be quickly tailored for additional requirements..
To install the source programs (the subprogram and a test program), and compile them, execute the bash script: downloads/stringStats.setup [md5: 1909a3d3ff3659b45117bc0faa9c2284]. Right click and save the script in the location where you want the source program to reside, then execute it. It will create two files containing the source programs, then execute the GnuCOBOL compiler to compile them into the run unit for the test program. The GnuCOBOL compiler must be installed prior to executing the bash script.
Output from the test/verification program:
jay@Phoenix ~ $ ./testSubs String>ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz>0123456789-< Length: +0065 First character: A Last character: - Numeric: +0010 Alpha: +0052 Upper: +0026 Lower: +0026 Spaces: +0001 Dashes: +0001 Commas: +0000 Other: +0001 String>Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live.< Length: +0498 First character: F Last character: . Numeric: +0000 Alpha: +0394 Upper: +0004 Lower: +0390 Spaces: +0088 Dashes: +0002 Commas: +0010 Other: +0004
If you want to be able to dynamically call the subprogram move the object module (stringStats.so) to a location included in your COB_LIBRARY_PATH.
* Updated September 20, 2019 * I was tired of looking for and copying the Working-Storage fields for this, and a few other, routines, so I updated the installation script to provide a copybook that may be used in the calling program for this routine. For easiest use, you should copy the copybook file into the directory that GnuCOBOL searches during compile time for copy books (on my Linux system that is /usr/local/share/gnucobol/copy).
This page was last updated on September 20, 2019.