DOORS DXL Tutorial

DOORS DXL Tutorial Part 4

In this series of articles, I am going to explain to you IBM DOORS DXL scripting from scratch. So, if you are a beginner in DXL scripting, hopefully, this article would help you. This is part-4 of the DOORS DXL tutorial.

So, if you are looking for a starting point to learn DXL scripting, you are on the right page! I know, we have the DXL reference manual and it’s a bit concise and difficult to grasp for beginners, especially if you do not have any previous experience in other programming languages.

In the previous article (Part-1,2,3), I explained how to write a simple Hello World program and data types. In this article series, we will mainly discuss the DXL string.

String in DXL

DXL String starts enclosed in quotes (“). String in DXL is similar to char * in c programming. The string in DXL can contain any number of characters and it can be treated as an array of characters. A DXL string can also contain control characters such as “\n”, “\t” etc.

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.1.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

string str = "www.TheCloudStrap.Com";

//print the string
print(str "\n");

// parenthesis for print function is optional
print str "\n";
DOORS DXL Tutorial - Output

DXL String Concatenation

You can concatenate two strings by using the DXL string concatenation operator i.e. space character (” “). When you concatenate two strings the rightmost element of the expression must be a string.

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.2.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

string myStr1 = "www";
string myStr2 = "TheCloudStrap";
string myStr3 = "com";

// String concatenation operator in DXL - space character
// Concatenate these strings variables myStr1, myStr2, myStr3, myStr4, and myStr5
string myWebName = myStr1 "." myStr2 "." myStr3;

// print the concatenated string
print(myWebName);
DOORS DXL Tutorial - Output

Extract Substring from a DXL String

We can extract the substring from a DXL string by using the string indexing method. The DXL string indexation is indicated by [ ]. If you want to extract a particular character from a string, you need to mention the index of the character inside [ ]. The DXL string indexing is similar to the C programming language. The index of the first character in the string is 0, for the second character it is 1, and so on. So, if you mention, str[0], you would get the first character of the string str.

But, if you want to extract a substring from a string, you just need to mention the index range inside [ ]. For example, if you want to extract the first three characters from a string str, you can do the following – str[0:2].

string str [range]

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.3.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

string myStr = "www.TheCloudStrap.Com";

// Extract a character from the string str
char myCh = myStr[0];
print(myCh);
print("\n");

// Extract a substring from myStr
string mySubStr = myStr[0:2];
print(mySubStr);
print("\n");


// Extract another substring from myStr
mySubStr = myStr[4:16];
print(mySubStr);
print("\n");

// Extract another substring from myStr
mySubStr = myStr[18:20];
print(mySubStr);
print("\n");

4.3 DOORS DXL Tutorial Output

DXL String Functions

Here are the following string functions that are available in DXL:

  1. int length (string str)
  2. string upper (string str)
  3. string lower (string str)

Length of a DXL String

How to find out the length of a string in DXL? The length() function returns the length of the string str. Here is the syntax of the length() function in DXL:

int length (string str)

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.4.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/
string str = "www.TheCloudStrap.Com";

// Find out the length of the string - str
print(length(str));
4.4 DOORS DXL Tutorial Output

upper() and lower()

You can convert a string to lowercase by using the lower() and to upper case by using the upper() function.

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.5.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

string myStr = "www.TheCloudStrap.Com";

// convert myStr to lower case
string myStrLower = lower(myStr);
print(myStrLower);
print("\n");

// convert myStr to upper case
string myStrUpper = upper(myStr);
print(myStrUpper);
print("\n");
4.5 DOORS DXL Tutorial Output

DXL String Comparison

We can compare DXL string by using the following comparison operators:

== != <= < >= >

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.6.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

string myStr1 = "www.TheCloudStrap.Com";
string myStr2 = "www.thecloudstrap.com";

// compare two DXL strings
if(myStr1 == myStr2){
	print("String Match!\n");
}
else{
	print("No Match!\n");
}

// compare two DXL strings
if(myStr1 != myStr2){
	print("Strings do not Match!\n");
}
else{
	print("Match!\n");
}
4.6 DOORS DXL Tutorial Output

cistrcmp()

cistrcmp() is used to compare two strings without considering their case. So, this is a case insensitive string comparison function. This is a very useful DXL string function.

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.7.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

string myStr1 = "www.TheCloudStrap.Com";
string myStr2 = "www.thecloudstrap.com";

// compare two DXL strings using cistrcmp()
print(cistrcmp(myStr1,myStr2));

// print "PASS" if both string are same (case insensitive)
if(0 == cistrcmp(myStr1,myStr2)){
	print("PASS");
}
else{
	print("FAIL");
}
4.7 DOORS DXL Tutorial Output

String matching

You can use the following function to find the string match:

bool matches ( string pattern, string str )

Here is a DXL script example:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d4.8.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

string myStr = "The test: TEST-005 is FAILED at Line Number-128.";

if(matches("FAIL",myStr)){
	print("TEST Failed!\n");
}

if(matches("fail",myStr)){
	print("TEST Failed!");
}
else{
	print("TEST - No status");
}

4.8 DOORS DXL Tutorial Output

Conclusion

This was part-4 of the DOORS DXL tutorial. The intention of this article was to familiarize you with DOORS DXL and show you different data types that are supported by DXL scripting. Please comment below if you have any questions/suggestions.

In the next DOORS DXL tutorial, I will discuss about the strings and how to use strings in DXL.

DOORS DXL – String operation

One thought on “DOORS DXL – String operation

Comments are closed.

Scroll to top
error: Content is protected !!