This week I’ve discovered the power of the string handling syntax that’s built into the Managed COBOL language. If you're not familiar with it, it’s well worth a look...
We'll start by looking at a code sample, then we'll discuss the syntax.
The program produces the output :
hello world hello world hello-world 23 is a number which I can concatenate Length of a = 11 hello-world Micro Focus Managed COBOL is amazingly good for working with strings!
Now let's take a closer look at the code...
Substrings
Substringing is built into the Managed COBOL syntax
To do this with C# or Java you would have to use a substring method on the string class.
String Length
To get the length of a string use SIZE OF, for example
To do this with C# or Java you would have to use a length method on the string class.
String Concatenation
String concatenation is easy in COBOL using the & operator.
Notice in the example above that you can concatenate
- string variables eg a & b
- substrings eg a & b(1:3)
- quoted string constants eg a & "-"
- non-string types eg 23 & " is a number"
- return values from invokes eg in the example above - type COBOLString::Split
- and most impressively a combination of the above!
NB All the sample code above will compile to .NET or JVM. For an overview of .NET COBOL & JVM COBOL please see "Managed COBOL - An Overview".
#JVM
#development
#VisualCOBOL
#COBOL
#language
#.net
#Eclipse
#VisualStudio
#HowTo-BestPractice