Jump to content
Sign in to follow this  
Guest rkruijer

Answers on String Manipulation

Recommended Posts

Guest rkruijer

Do you recognize this list? Looking in our forum I have noticed that any questions on the subject of string manipulation will get very little response if any. With this tutorial I will try to put an end to that. Took me some time to sort it out and I will share it with you today.The examples below can be reconstructed and/or combined. I will give you only the essentials!lc Converts a string to lowercase.uc Converts a string to uppercase.cap Capitalizes a string.chr Converts a number to a symbol.ord Converts a symbol to an integer.scat Concatenates strings.schr Finds a symbol in a string.scmp Compares strings.scmi Compares strings, ignoring case.sstr Finds a substring.ssub Extracts a substring.symb Extracts a single character.slen Will return the length of a stringThe ord instruction converts a symbol also called character into it's ascii code (integer) The chr instruction converts an ascii code (integer) into a character or symbol if you like. They are the same. - slen - Example 1. Length of the designation string '01L-19R' Will return 7 (@c:WaypointAirportRunwayDesignation) slen (>;L:Rqylength, number) - scmp - Example 2. Compare strings. If equal will return -1 With the '!' added it will return 1 so if{} can be used. (@c:NearestAirportCurrentIdent,string) 'EHAM' scmp ! (>L:Var5, bool) - scmp - Example 2a. Compare strings. Test String for Airport ICAO. 0 (>L:TransitionLevel,enum) c (@c:NearestAirportCurrentIdent,string) sp0l0 'EHAM' scmp ! if{ 40 } l0 'EGLL' scmp ! if{ 70 }(>L:TransitionLevel,enum) - sstr - Example 3. Find a substring. Test ICAO string for Country.(@c:NearestAirportCurrentIdent,string) sp0 l0 'EH' sstr ! if{ 3000 } l0 'EG' sstr ! if{ 6000 } l0 'ED' sstr ! if{ 5000 } (>L:Inflight_TA,number) - schr - Example 4. Find a character in a string. Will return the position of the symbol starting with 0 in the string '01L-19R' 'L' L:found will return 2 'R' will return 6(@c:WaypointAirportRunwayDesignation) 'L' ord schr (>L:Lfound,number) (@c:WaypointAirportRunwayDesignation) 'R' ord schr (>L:Rfound,number) - ssub - Example 5. Extract part of a string. From '01L-19R' '01L' will be extracted. The result cannot be entered into a variable but it can be printed!Notice the 0 3. 0 is the starting point and 3 the length%Deel1 %((@c:WaypointAirportRunwayDesignation) 0 3 ssub)%!s!- ssub - Example 5a. Extract part of a string. From 'Amsterdam' 'ster' will be printed.Notice that here only one pare of brackets must be used! %Substr %( 'Amsterdam' 2 4 ssub )%!s! - uc - Example 6. Output in uppercase From 'Amsterdam' 'ster' will be converted to 'STER'%Substr %( 'Amsterdam' 2 4 ssub uc)%!s! - cap - Example 7. First symbol will be converted to capital. From 'Amsterdam' 'ster' will converted to 'Ster' %Substr %( 'Amsterdam' 2 4 ssub cap)%!s! - symb - Example 8. Extract one character. From '01L-19R' 'L' will be printed.Notice that only the pointer 2 is required. %((@c:WaypointAirportRunwayDesignation) 2 symb)%!s - symb - Example 8a. Extract one character. From 'Amsterdam' 'A' will be printed.%( 'Amsterdam' 0 symb )%!s! - scat - Example 9. Concattenation. Given: L:Var1=49 L:Var2=53 L:Var2=53 'KLM153' (my callsign) will be printed.Notice that the respective ascii codes are first converted to a symbol/character and then added.%( 'KLM' (L:Var1,enum) chr scat (L:Var2,enum) chr scat (L:Var3,enum) chr scat )%!s! - lc - Example 10. Another example? I've done my share. I will leave this lowercase instruction to you!Roelof Kruijer

Share this post


Link to post
Share on other sites
Guest ridgell

great post ! thxa copy and paste for my fs9 bible

Share this post


Link to post
Share on other sites
Guest iagman

Roelof,Thanks for taking the time to share this information. Teaching by example is my kind of cake.Glenn

Share this post


Link to post
Share on other sites
Guest rkruijer

Thank you Gentleman for appriciating this effort.A better readable and slightly changed Word document can be found at my site: http://members.home.nl/rkruijer/ Go to the English Page! You will find the link at the top!Roelof

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...