String Manipulation in XML by Roelof Kruijer - DOC by ncz44837

VIEWS: 21 PAGES: 2

									                                  String Manipulation in XML by Roelof Kruijer
Do you recognize this list? Looking in our Avsim Forum or on Internet you will notice that very little seems to be known on the
subject of string manipulation. 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 string

The 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 and are needed to find or print a character in/from a string.


- slen - Example 1. Length of the designation string '01L-19R' Will return 7

<Element>
<Select>
<Value>(@c:WaypointAirportRunwayDesignation) slen (>;L:Rqylength, number) </Value>
</Select>
</Element>

- scmp - Example 2. Compare strings. If equal will return -1 With the '!' added it will return 1 so if{} can be used.

<Value>(@c:NearestAirportCurrentIdent,string) 'EHAM' scmp ! (>L:Var5, bool) </Value>

- scmp - Example 2a. Compare strings. Test String for Airport ICAO.

<Value> 0 (>L:TransitionLevel,enum) c (@c:NearestAirportCurrentIdent,string) sp0
l0 'EHAM' scmp ! if{ 40 }
l0 'EGLL' scmp ! if{ 70 }
(>L:TransitionLevel,enum) </Value>

-sstr - Example 3. Find a substring. Test ICAO string for Country. Notice that 1 character is considered a
        Substring

<Value>(@c:NearestAirportCurrentIdent,string) sp0
l0 'EH' sstr ! if{ 3000 }
l0 'EG' sstr ! if{ 6000 }
l0 'ED' sstr ! if{ 5000 }
l0 'K' sstr ! if{ 18000 }
(>L:Inflight_TA,number) </Value>



- 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)
</Value>



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

<Element>
<Position X="1" Y="37"/>
<Text X="88" Y="14" Bright="Yes" Length="22" Font="Arial" FontSize="10" Color="#00FF00">
<String>%Deel1 %((@c:WaypointAirportRunwayDesignation) 0 3 ssub)%!s!</String>
</Text>
</Element>

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

<String>%Substr %( 'Amsterdam' 2 4 ssub )%!s!</String>

- uc - Example 6. Output in uppercase From 'Amsterdam' 'ster' will be converted to 'STER'

<String>%Substr %( 'Amsterdam' 2 4 ssub uc)%!s!</String>

- cap - Example 7. First symbol will be converted to capital. From 'Amsterdam' 'ster' will converted to 'Ster'

<String>%Substr %( 'Amsterdam' 2 4 ssub cap)%!s!</String>

- symb - Example 8. Extract one character. From '01L-19R' 'L' will be printed.
         Notice that only the pointer 2 is required.

<String>%((@c:WaypointAirportRunwayDesignation) 2 symb)%!s!</String>

- symb - Example 8a. Extract one character. From 'Amsterdam' 'A' will be printed.

<String>%( 'Amsterdam' 0 symb )%!s!</String>

-scat - Example 9. Concattenation. Given: L:Var1=49 L:Var2=53 L:Var2=53 'KLM153' (my call sign) will be
       printed. Notice that the respective ascii codes are first converted to a symbol/character

<String>%( 'KLM' (L:Var1,enum) chr scat (L:Var2,enum) chr scat (L:Var3,enum) chr scat )%!s!</String>

- lc - Example 10. Another example? I've done my share. I will leave this lowercase instruction to you!

This document is copyrighted and may not be used as part of another document, tutorial or the likes.
It may not be distributed or made available by third parties. You may however post a link to my site:
http://members.home.nl/rkruijer/ by Roelof Kruijer 8/13/2006

								
To top