Skip to main content
Kat
Employee
Jul 31, 2023 11:50 AM UTC
Solved

How to TRIM Output/Buffer Value

I want to trim the Left and Right of text whitespaces from value of buffer/output, how can I do trimming in Text ?

 

[Originally asked and solved on Support Hub]

Community Manager
Jul 31, 2023 11:51 AM UTC

You can use the following syntax to remove spaces at either end of your string. Assuming the you have the string stored in a buffer variable called "Variable" :

{CALC[TRIM("{B[Variable]}")]}

 

Use the TC Set Buffer generic module in your test case as follows:

For the value of the Sub attribute "Buffer" use the same variable name i.e. Variable

For the value of the sub attribute "Value" use the syntax given above i.e. {CALC[TRIM("{B[Variable]}")]}

 

The result of the execution will be stored in the buffer variable "Variable"

14 replies

Community Manager
Jul 31, 2023 11:51 AM UTC

You can use the following syntax to remove spaces at either end of your string. Assuming the you have the string stored in a buffer variable called "Variable" :

{CALC[TRIM("{B[Variable]}")]}

 

Use the TC Set Buffer generic module in your test case as follows:

For the value of the Sub attribute "Buffer" use the same variable name i.e. Variable

For the value of the sub attribute "Value" use the syntax given above i.e. {CALC[TRIM("{B[Variable]}")]}

 

The result of the execution will be stored in the buffer variable "Variable"

Kat
KatEmployeeAuthor
Employee
Jul 31, 2023 11:52 AM UTC

I am getting Error that "No suitable value found for command 'CALC' , Can you tell me what is wrong here

Quality Matters, Kat
Community Manager
Jul 31, 2023 11:52 AM UTC

When your value comes from your application under test, you can also use the verify action mode, then use the XB-Syntax so the value gets buffered without white spaces - for instance, you've got "My Text" in the application, and you only want "Text" in your Buffer, verify against: My {XB[Variable]} - that should store it without white spaces in there.

Kat
KatEmployeeAuthor
Employee
Jul 31, 2023 11:53 AM UTC

I want just a part of a huge string from character 6 to 14.

 

Just use Partial Buffer Module from : /Modules/Standard modules/TBox Automation Tools/Buffer Operations/TBox Partial Buffer

Quality Matters, Kat
Community Manager
Jul 31, 2023 11:54 AM UTC

Use following in TBOX SET BUFFER MODULE.

Suppose your Buffer has value :  ToscaUser001

 

{CALC[LEFT(""""{B[UserName]}""", 5)]}   = Tosca

{CALC[RIGHT(""""{B[UserName]}""", 3)]}   = 001

Kat
KatEmployeeAuthor
Employee
Jul 31, 2023 11:54 AM UTC

I needed to add a " after the 3 or 5 in your example for it to work in version 11.

{CALC[RIGHT(""""{B[UserName]}""", 3")]}   = 001

Quality Matters, Kat
Kat
KatEmployeeAuthor
Employee
Jul 31, 2023 11:54 AM UTC

Can i have like this ?

if value= "Tosca123"

i need only="sca123"

is that possible?

Quality Matters, Kat
Community Manager
Jul 31, 2023 11:54 AM UTC

The original example will work in TBox as long as you remember the quadruple-double-quote rule on strings. In other words, use {CALC[TRIM(""""{B[Variable]}"""")]} instead of {CALC[TRIM("{B[Variable]}")]}.

Kat
KatEmployeeAuthor
Employee
Jul 31, 2023 11:55 AM UTC

I am trying to truncate extra spaces before and after a value I have buffered.

However, when I tried using {CALC[TRIM(""""{B[Variable]}"""")]} format, TOSCA has returned the value as '{B[Variable]}'.

When I tried using {CALC[TRIM("{B[Variable]}")]} format, TOSCA returns the following error:

"The expression 'TRIM(<BufferValue>)' is not valid in MS-Excel formulas. For Details, please paste the expression to MS-Excel."

 

Could you please let me know, if I am missing some important detail here?

Quality Matters, Kat
Community Manager
Jul 31, 2023 11:55 AM UTC

 found a solution using the module TC String Operation: