Highlighted
Honored Contributor.
Honored Contributor.
542 views

How I can access only the last 2 letters of a word.

Hi Experts,

As part of implemenating a scenario in connect IT I want to take the last 2 letters of a word.

Could any one please help me to find a solution, that how I can consider only the last 2 letters of a word.

Thanks & Regards,

Sandhu Mol

0 Likes
5 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

How about Right() function in CIT:

Description: Returns the rights most iNumber characters of the string parameter.

Input parameters:
strString: Character string to process.
lNumber: Number of characters to return.

Example
Dim lWord, strMsg, rWord, iPos
strMsg = "Left() Test."
iPos = InStr(1, strMsg, " ")
lWord = Left(strMsg, iPos - 1)
rWord = Right(strMsg, Len(strMsg) - iPos)
strMsg=rWord+lWord
RetVal=strMsg

This returns the value Test.Left()
.

Highlighted
Honored Contributor.
Honored Contributor.

Thanks for your valuable replay.

The below script will give reverse of the string right.

So I just modified it as follows.

 

Dim ipos,rWord,strMsg

 

if([COMPONENT_NAME] = "pec-a") then

strMsg = [COMPONENT_VERSION]

end if

 

iPos = InStr(1, strMsg, "-")

rWord = Right(strMsg, Len(strMsg) - iPos)

 

if(rword="mb") then

Retval="Generation1"

else

PifIgnoreNodeMapping

end if

 

The script will work as follows:

It will consider the version name which will be having a hyphen (-).

Then it will take the position of that hyphen and consider the letters after the hyphen by subtracting it from the length of the word.

The that word will be compared using the if condition and save as Genaration1 if both are matching.

But I am getting only Null value though words with "mb" are present.

 

Could you please help me to resolve it.

Thanks in Advance.

Regards,

Sandhu Mol

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

What is your total string and what do you want to find there ?

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

The value of strmsg is "dp_fw.3.1.000-mb"

And I want to get the last 2 letters (mb) alone.

Then I have to compare it using if condition and if it matches I have to save Genenration1 to the press generation variable.

And if the last two letters are rd or g2 , I have to save it as Genaration2 and so on.

 

Thanks & Regards,

Sandhu Mol

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

I think you need use next function:
RightPart([strmsg],"-",0)
That's mean do not calculate last 2 symbols and just take all symbols which you have after "-" symbol. (ofcourse if that's hole string and you have nothing after that)
0 Likes
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.