How to remove trailing spaces from the DXL string?

How to remove trailing spaces from the DXL string?

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 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 DOORS DXL string, you can use the above functions.

How to remove trailing spaces from the DXL string?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top
error: