Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Displaying only part of a string

Featured Replies

  • Commercial Member

Hello allI was wondering if anyone new of an easy way to display only the first 12 characters of a string. I know the hard way would be to create a loop and output a character at a time but I'd like to try to avoid that if I could.I'm trying to output to screen a GPS waypoint frequency name ( %((@c:WaypointAirportFrequencyName))%!s! in the code snippet below). The problem is that on rare occasions this string can be rather long and can end up messing up the tabs in the rest of the line and thus messing the formatted text. I was hoping there would be an easy command that would just return the first 12 (or whatever number i enter) characters. I tried %!12s! but that just fills the string with blank space to make it a minimum of 12 characters long.Thanks for any help you can provide.

 <Element> // FREQUENCIES Right Column  <Visible>(L:EKP_AirportPage,number) 0 ==</Visible>  <Position X="230" Y="244"/>  <FormattedText X="220" Y="493" Font="Courier New" FontWeight="800" FontSize="20" VerticalAdjust="Center" Color="0x598a59" Bright="Yes" Tabs="0,120">   <String>    %((@c:WaypointAirportFrequenciesNumber) s2 21 >)     %{if}      %(22 sp1)      %{loop}       %(l1 (>@c:WaypointAirportCurrentFrequency))       %((@c:WaypointAirportFrequencyName))%!s!       %((@c:WaypointAirportFrequencyLimit))%{case}%{:1}\{dpl=RX}%{:2}\{dpl=TX}%{end}\t       %((@c:WaypointAirportFrequencyValue,Mhz))%!3.2f!\n       %(l1 ++ s1 l2 <)      %{next}     %{end}   </String>  </FormattedText> </Element>

www.antsairplanes.com

Hello Anthony,Someone that is good at xml will surely point out the trivial, elegant, right way to accomplish this, but in the meantime, another approach in addition to a loop that you alluded to might be to extract the first 12 characters in a macro:

	<Macro Name="Extract12Chars">	(@c:WaypointAirportFrequencyName) 0 symb	(@c:WaypointAirportFrequencyName) 1 symb scat	(@c:WaypointAirportFrequencyName) 2 symb scat	(@c:WaypointAirportFrequencyName) 3 symb scat	(@c:WaypointAirportFrequencyName) 4 symb scat	(@c:WaypointAirportFrequencyName) 5 symb scat	(@c:WaypointAirportFrequencyName) 6 symb scat	(@c:WaypointAirportFrequencyName) 7 symb scat	(@c:WaypointAirportFrequencyName) 8 symb scat	(@c:WaypointAirportFrequencyName) 9 symb scat	(@c:WaypointAirportFrequencyName) 10 symb scat	(@c:WaypointAirportFrequencyName) 11 symb scat	</Macro>

then in your display element, substitute%(@Extract12Chars,string)%!s!in place of%((@c:WaypointAirportFrequencyName))%!s!Anyway ... this might work...... I dunnoBob

Hello Anthony,Someone that is good at xml will surely point out the trivial, elegant, right way to accomplish this, but in the meantime, another approach in addition to a loop that you alluded to might be to extract the first 12 characters in a macro:
	<Macro Name="Extract12Chars">	(@c:WaypointAirportFrequencyName) 0 symb	(@c:WaypointAirportFrequencyName) 1 symb scat	(@c:WaypointAirportFrequencyName) 2 symb scat	(@c:WaypointAirportFrequencyName) 3 symb scat	(@c:WaypointAirportFrequencyName) 4 symb scat	(@c:WaypointAirportFrequencyName) 5 symb scat	(@c:WaypointAirportFrequencyName) 6 symb scat	(@c:WaypointAirportFrequencyName) 7 symb scat	(@c:WaypointAirportFrequencyName) 8 symb scat	(@c:WaypointAirportFrequencyName) 9 symb scat	(@c:WaypointAirportFrequencyName) 10 symb scat	(@c:WaypointAirportFrequencyName) 11 symb scat	</Macro>

then in your display element, substitute%(@Extract12Chars,string)%!s!in place of%((@c:WaypointAirportFrequencyName))%!s!Anyway ... this might work...... I dunnoBob

Try(@c:WaypointAirportFrequencyName) 0 11 ssub ssub Extracts digits. ie. 3 9 ssub gives text 4th to 10th inc. from WaypointAirportFrequencyName. Put it in a macro

Paul EGLD

  • Moderator
Try(@c:WaypointAirportFrequencyName) 0 11 ssub ssub Extracts digits. ie. 3 9 ssub gives text 4th to 10th inc. from WaypointAirportFrequencyName. Put it in a macro
I've never tried that, but if it does work, then the FSX SDK is (as usual!) very misleading...
StringOperator   Description          #Operators   Example          Resultssub       Extracts a substring     2      'ab' 'abcde' ssub  'cde' 

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Author
  • Commercial Member

Thanks for the ideas guys.I'll try the suggestions and see what works best.The other crude way I was thinking of was to just to duplicate the element and only output the string and then limiting the x size prevents any overlapping (I did say it was crude didn't I ?).

www.antsairplanes.com

  • Author
  • Commercial Member

Well, I have a go at seeing what works and doesn'tPaul (pve) is 100% correct ! (and the SDK is wrong, again :) )%((@c:WaypointAirportFrequencyName) 0 11 ssub)%!s!outputs the first 11 characters of the frequency name and is just what I was looking for (and works a treat).It seems then that ssub can take 3 parameters.The first being the string.The second is the number of characters to start extraction from (with 0 being the left most)The third being the number of characters to extract.I don't know whether the example that Bill quoted above in the SDK actually works or not. I've never had a need to do what the SDK example describes.BTW In case anyone was wondering. The only time I have found the frequency name being longer than 10 characters is ay big airports where they might have a "Clearance Pre-Taxi" frequency name.Thanks for everybody who replied. Much appreciated.On another note:Here are some examples of messing with the !s! output character that I tried to see if I could get the result I was after. I thought I would try a decimal place and see what effect that had. It looks like the decimal will extract a substring but starting from the right (it would have been more useful if it started from the left). I don't know why anyone would want to just display a subset of characters from the right hand side but if you do try putting in a decimal place into the !s! Freq name = is the value being returned from (@c:WaypointAirportFrequencyName)output is what is displayed on screen"-" indicates a blank space added to the output%((@c:WaypointAirportFrequencyName))%!5s! Freq name = "Approach" output "Approach" Freq name = "Atis" output "-Atis"5s simply adds leading spaces to fill the string to a minimum of 5 characters%((@c:WaypointAirportFrequencyName))%!.5s! Freq name = "Approach" output "roach" Freq name = "Atis" output "Atis".5s will extract the 5 right most characters from the string. It will not add leading spaces to strings less than 5 characters long.%((@c:WaypointAirportFrequencyName))%!10.5s! Freq name = "Approach" output "-----roach" Freq name = "Atis" output "------Atis"10.5s extracts the 5 right most characters from the string and then adds leading spaces to fill the string to 10 characters.

www.antsairplanes.com

  • Moderator
Paul (pve) is 100% correct ! (and the SDK is wrong, again :) )<snipped for brevity>I don't know whether the example that Bill quoted above in the SDK actually works or not. I've never had a need to do what the SDK example describes.
Well not "wrong" so much as misleading and incomplete... :( I haven't either, which is why I never bothered even looking at 'ssub' to begin with!Thanks to everyone, especially Paul for providing me my "new thing learned today..." :Applause:Now I wonder if the last parameter could be an (L:var,enum)? It would be interesting if it did...

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Fr. Bill,,

Now I wonder if the last parameter could be an (L:var,enum)? It would be interesting if it did...
I thought the same thing,, decided to give it a try. Roger that,,,,,, it does work :-) A little example below w/ a touch of humor LOL!Roman
<Update>(P:Absolute time,seconds) 0.3 % 0.15 > ! if{ (G:var1) 235 == if{ 0 (>G:Var1) } els{ (G:Var1) ++ (>G:Var1) } }'This is a test for string manipulation.... I hope you like this example... Imagine making one of those programmable advertising signs to do really cool stuff :-)                           	REPEATING NOW  ' 0 (G:Var1) ssub s1</Update><Element><Visible>(G:Var1) 209 < (P:Absolute time,seconds) 0.5 % 0.25 > ! ||</Visible><Position X="0" Y="0"/><Text X="150" Y="20" Bright="Yes" Length="300"  Color="Red" FontWeight="800" Adjust="Right"><String>%(l1)%!s!%</String></Text></Element>

20AUG21_Avsim_Sig.png?dl=1  FS RTWR   SHRS F-111   JoinFS   Little Navmap 
 

 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.