Help please: Returned string has quotes


Xojo Version 2019 Release 1, macOS Catalina Version 10.15.7
I have this method which returns a string but the returned string is in quotes.

Msgbox "TheSerialNumberString is " + TheSerialNumberString
TheSerialNumberString is “C07P70SAG1J2”

I was expecting
TheSerialNumberString is C07P70SAG1J2

Why is that?

Public Function SystemSerialNumber() as String
dim sh as New Shell
Dim y as String

#If TargetWin32 Then
sh.TimeOut = 3000
sh.execute(“wmic bios get serialnumber”)
return trim(NthField( sh.Result, “SerialNumber”, 2 ))
#ElseIf TargetMacOS Then
sh.Execute(“ioreg -l | grep IOPlatformSerialNumber|awk ‘{print $4}’”)
y = sh.result
y = replace(y,"<"+chr(34),"")
y = replace(y,chr(34) + “>”,"")
return y

If sh.ErrorCode = 0 then return (sh.Result)
End Function



My guess is that you are trying to replace <" and "> but Catalina only needs you to replace "

In other words, try this:

y = ReplaceAll(y,chr(34),"")

to make y the value without quotes

Hi AlbertoD,

I made the change and the quotes are gone, thanks.

But if i do this:
If app.SystemSerialNumber = “C07P70SAG1J2” then Msgbox “Success”
I get no response,

But Msgbox "app.SystemSerialNumber is " + app.SystemSerialNumber
gives app.SystemSerialNumber is C07P70SAG1J2

Why is that?



I would bet that the original call has a trailing line ending. Try trimming that string after replacing the quotes.

1 Like

Yes, Indeed, Greg, Trim worked.
Thanks again.

May I suggest to check WindowsWMIMBS class in MBS Xojo Win Plugin and SystemInformationMBS module in MBS Xojo Util Plugin.
They can get your the information more directly without shell output parsing.