INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: How to compare a string to a number?  (Read 1298 times)

tranquilo

  • Recent member
  • *
  • Posts: 8
How to compare a string to a number?
« on: September 05, 2008, 12:56:42 pm »

I have a user library field of data type string that contains a year and other characters, like "1977ABC...etc", and would like to create a Smartlist where one of the rules checks if the standard field "Year"  (converted to a string) is equal to the first four characters of the user defined field. Sort of like Str([Year])=Mid([MyStringField],0,4).

I have looked at the functions wiki, and found Mid(), but cannot find a function to convert "Year" to a string.

Help?

Edited to add: using MC 12.0.530
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: How to compare a string to a number?
« Reply #1 on: September 05, 2008, 03:27:29 pm »

i guess
Code: [Select]
if(isequal([year],[MyStringField],8),yeah,hell no), where yes means they are equal, could work.
i did not test it in my machine. but when it does not work. please say so.

 :)
gab

did test it... this worked for me:
Code: [Select]
if(isequal([year],mid([test],0,4),8),yeah,hell no)
Logged

tranquilo

  • Recent member
  • *
  • Posts: 8
Re: How to compare a string to a number?
« Reply #2 on: September 05, 2008, 04:23:23 pm »

Thanks!

Yes, the first solution didn't work as posted, but it gave me a start to try different combinations, so I arrived at one almost the same as your second suggestion:

[=isequal([Year],Mid([MyStringField],0,4),0)]=1

I opted for compare type 0 because with Mid() I can go for a exact match.

Much appreciated; would never have found it without your help.
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: How to compare a string to a number?
« Reply #3 on: September 05, 2008, 04:46:06 pm »

nice that you found it. yes, the 8 was a left over from my first try.. 0 makes more sense in this case.

 :)
gab
Logged
Pages: [1]   Go Up