Remove trailing spaces from the DXL string

IBM DOORS DXL String
IBM DOORS DXL String

In the context of DXL, a string is a sequence of characters. It’s a fundamental data type, and it’s used widely for storing, managing, and manipulating text-based requirement data within DOORS. While it may appear simple on the surface, mastering DXL strings can empower users to handle complex data more effectively, making requirements management a more streamlined process.

The string manipulation capability of DXL is extensive. From simple operations like concatenating two strings, extracting substrings, or replacing a part of a string, to more complex functions like pattern matching and regular expressions, DXL offers a plethora of possibilities.

Let’s consider a practical example to demonstrate the potential of DXL string manipulation. Suppose you need to extract specific information from a large set of requirements, and the desired information is buried within the text. By using DXL strings and associated functions, you can automate the extraction process, significantly reducing time and effort.

Furthermore, DXL strings allow for more advanced data handling, such as parsing. Parsing a string means breaking down a larger piece of text into smaller, more manageable components. This is particularly useful when dealing with complex or structured text data in DOORS.

If you are working in DOORS DXL scripting, you may have to deal with DXL string. Sometimes, while exporting the data from the DOORS module, you may have trailing spaces at the end of the string, which you need to delete. In this article, we will mainly discuss how to remove trailing spaces in DOORS DXL.

There could be several ways to delete/remove trailing spaces in a DXL string. Here is the code that I could come up with:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: trimTrailingSpace.dxl
* $DESCRIPTION: Remove trailing space from a DXL string.
*
* 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
*		thecloudstrap {at} gmail.com
************************************************************************/

string trimTrailingSpaces(string s)
{
	int iPos = length(s) - 1
		
	while(isspace(s[iPos]))
	{
		iPos--
		if(iPos < 0) return ""
	}
	
	return s[0:iPos]
}

//----------------------------------------
// Main Code
//----------------------------------------

string myStr = "www.thecloudstrap.com       "
int len

len = length(myStr)
print(len " " myStr "\n")

myStr = trimTrailingSpaces(myStr)

len = length(myStr)
print(len " " myStr)
How to remove trailing spaces from the DXL string?

As you can see in the above output, the function is able to remove the trailing spaces from the given string.

How to remove leading spaces in DOORS DXL?

Now, let us see how to remove the leading spaces from a string in DOORS DXL:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: trimLeadingSpace.dxl
* $DESCRIPTION: Remove leading space from a DXL string.
*
* 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
*		thecloudstrap {at} gmail.com
************************************************************************/

string trimLeadingSpaces(string s)
{
	int pos = 0

	while(isspace(s[pos]))  
	{
		pos++
		if(pos > length(s)) return ""
	}
	return s[pos:]
}

//----------------------------------------
// Main Code
//----------------------------------------
string myStr = "            www.thecloudstrap.com"
int len

len = length(myStr)
print(len " " myStr "\n")

myStr = trimLeadingSpaces(myStr)

len = length(myStr)
print(len " " myStr)

we have defined a function i.e. trimLeadingSpaces() to remove the leading spaces from a DXL string. The idea is to start a while loop and keep iterating the loop until it finds a non-space character. Once we find a non-space character, the while loop ends and returns the string without the leading spaces. Let’s see the output:

How to remove leading spaces from the DXL string?

So, if you need to remove leading or trailing spaces in the DOORS DXL string, you can use the above functions.

In conclusion, DOORS DXL (Dynamic Object-Oriented Requirements System, DOORS Extension Language) offers a robust and flexible approach to requirements management. The potential in DXL string manipulation specifically, stands out. It allows parsing, analyzing, and modifying textual data within DOORS, optimizing the process of handling complex requirement data. Despite its learning curve, proficiency in DXL strings significantly enhances one’s ability to manage and manipulate data within the DOORS environment, paving the way for better, more efficient requirements management.

How to remove trailing spaces from the DXL string?
Scroll to top
error: Content is protected !!