Jump to content
Sign in to follow this  
n4gix

Compare part of a string

Recommended Posts

Guest rkruijer

Hi,I need to be know how I can have XML to compare the first 2 letters from a 4 letter string. Example:string="EHAM" or "EGLL". The first 2 letters are for the country.I need to know what country it is by comparing the first 2 letters.from that string.Can anyone help?Roelof.

Share this post


Link to post
Share on other sites
Guest rkruijer

This subject does not give a lot of response (none) so I started digging a bit.After Jan had pointed out to me how to obtain information directly from the gps.dll I learned from him how to handle(@c:NearestAirportCurrentIdent,string) 'EHAM' scmp ! if{}What I wanted was to compare the first 2 letters to see what country I am in. After some trial and error I found out how this sstr (find substring) works. Like all programmers I thought about a way to work with substr(VAR,1,2) which would give 'EH' Tried it in about every form but it does not work. Then I did this.....(@c:NearestAirportCurrentIdent,string) 'EH' sstr ! if{ 30 (>L:AP,number) } Eureca!Note the "!". XML seems to have most of it upside down! (-: If you need to print it you could use something like: (L:AP,number) 30 == EH or THE NETHERLANDSI know it is primitive and not fool proof because there might be an airport 'EGEH' in England and that would give the same result I'm afraid. I wonder if any of these guys from Microsoft would know the ins and out about these so called functions! It would be good to have a friend overthere. :) Roelof

Share this post


Link to post
Share on other sites
Guest Vorlin

Am I loosing one of my last two brain cells or did you just put up an example of a string variable in MSXML for FS9? And you have it working?I was under the impression that string vars weren't implemented and were impossible to emulate. Nick, Tom, I and others were mentioning the need for them in XML for FSX in the FSX forum.What am I missing here? Is there anything I can study in some GPS code somewhere that shows how to use strings in vars or, it appears above, in a macro that can be typed as a string and used as a var?Scott / Vorlin

Share this post


Link to post
Share on other sites

Unfortunately there's still (never has been) a way to store a string in a custom variable, but as he pointed out you can interpret a numeric value as a string in a macro for printing after using comparative operators on variables that do contain strings.(@1)%{case}%{:0}%A%{:1}%B%{:2}%C%{:3}%D%{:4}%E%{:5}%F%{:6}%G%{:7}%H%{:8}%I%{:9}%J%{:10}%K%{:11}%L%{:12}%M%{:13}%N%{:14}%O%{:15}%P%{:16}%Q%{:17}%R%{:18}%S%{:19}%T%{:20}%U%{end} .. etc...Then:%@ALPHA((L:String Value, enum))Why (SomeString, string) 'AB' sstr ! actually means a match IS found is a mystery(%!%!s!)--Jon

Share this post


Link to post
Share on other sites
Guest rkruijer

>What am I missing here? Is there anything I can study in some>GPS code somewhere that shows how to use strings in vars or,>it appears above, in a macro that can be typed as a string and>used as a var?>>Scott / VorlinNo Scott. What I do is find the occurence of 'EH' or 'EG' from what is found in the nearest airport string that is obtained by using the gps.dll. See the syntax for that. Being on Amsterdam Schiphol will give 'EHAM' Making use of the sstr syntax I discovered I can see if 'EH' is part of that string. When it comes to 0 (one would expect 1) the sstr has found the occurence of the 2 letter string. You cannot put that string in an L:Var but when you get a 0 (thus found) you can assign a number to an L:var representing the country. (@c:NearestAirportCurrentIdent,string) 'EH' sstr ! if{ 30 (>L:Country,number) } I know that if L:Country,number is 30 I am in Holland and if it is 31 I am in England et. etc. The numbers are just my numbers.By just checking the value of L:Country,number I can then printwhatever I like to print. When it is 30 I print HOLLAND when it is 31 I have the gauge print ENGLAND Checking for 10 countries would take up 10 lines like: (@c:NearestAirportCurrentIdent,string) 'EH' sstr ! if{ 30 (>L:Country,number) } Just the string to search for would change. e.g. 'EH', 'EG' etc.There may be a better way but this is the way I do it.Roelof

Share this post


Link to post
Share on other sites

>Why (SomeString, string) 'AB' sstr ! actually means a match IS>found is a mystery(%!%!s!)Actually, it makes perfect sense, if you stop to think about what's actually happening...When you are comparing "string values", the only time they would "match" is when the result of "subtracting them" results in zero!...AB - AB = 0"Letters" are only ASCII numbers, after all... ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...