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

  • 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()
    .

  • 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

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

  • 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

  • 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)