Jump to content
AndrewHoward

Why do these 2 statments produce different results ?

Recommended Posts

Hi,

Why do these two statemets give different results ?

Pos('#$02','bla,bla,#$02,bla');// Pos = 9 

 

const
  STX=#$02;

Pos(STX,'bla,bla,#$02,bla'); // Pos = 0

 

Thanks

Share this post


Link to post

const STX=#$02;

isn't the same as

const STX='#$02';

  • Like 2

Share this post


Link to post
40 minutes ago, AndrewHoward said:

Why do these two statemets give different results ?

'#$02' (w/ quotes) is a string literal consisting of 4 distinct characters: '#', '$', '0', '2'.  The string you are searching, 'bla,bla,#$02,bla', contains that 4-char substring in it, hence the result is > 0.

 

#$02 (w/o quotes) is a single Char whose numeric value is 2.  The string you are searching does not contain that character in it, hence the result is 0.

Edited by Remy Lebeau
  • Like 2
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×