Wednesday, November 13, 2019

String comparison for last few characters

Powershell Task:

I have two strings.

string1 : Data Capturer 2020 R1 (64-bit)
string 2 : Data Modifier 2020 R1 (64-bit)

The above 64-bit can sometimes 32-bit also.

Your task is to check string 1 and 2 and print message as "Same architecture" if both are same numbers (32-bit/64-bit)
If one is 32 and other is 64 then message should be "Both are different"

Solution:



Function checkArchValues($string1,$string2)
{
  $string1 = $string1.Trim()
  $string2 = $string2.Trim()
  $string1 = ($string1[-7..-6]) -join ""
  $string2 = ($string2[-7..-6]) -join ""
  if ($string1 -eq $string2)
  {
    return $true
  }
  else
  {
 return $false
  }
}

checkArchValues string1 string2

No comments:

Post a Comment