Our vBulletin migration is complete.
Welcome vBulletin users! All content and user information from the Micro Focus Forums (vBulletin) site has been migrated to this site. READ MORE.

String Handling in Managed COBOL

String Handling in Managed COBOL

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".



DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Comments

I was looking all over the web for the syntax:

  set n to size of myString.

Thanks a lot.

Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2012-06-21 16:58
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.