Text Formatting and String Operations
Good text formatting makes an add-on feel polished, readable, and reliable.
The most important rule is to keep data clean internally, then format it only at the last moment. Use numbers for calculation. Use display formatting when showing values to the user. Use export formatting when writing values to a file.
This separation keeps add-ons easier to understand and avoids subtle mistakes with units, localization, and precision. It also lets exported files remain stable and easy to process, while the user interface can still follow the user's preferred units and language.
Tacview’s API includes helpers for string manipulation, general text formatting, user-facing display, localization, and export-safe formatting. Use them instead of rewriting the same text handling logic in every add-on.
String operations
String operation helpers make common text changes easier.
Use them when you need to replace text, split a string into parts, or remove extra spaces.
They are especially useful in Lua add-ons, where the built-in string tools are more limited than in larger frameworks.
Examples:
General formatting
General formatting functions help you build clear text from values.
Use FormatString() when you need to combine text, numbers, or other values into a message.
For example, log functions use the same placeholder style:
General formatting does not automatically apply user unit preferences. For values such as altitude, distance, coordinates, speed, or time, prefer the dedicated display formatting functions below.
Display formatting
Display formatting functions convert internal values into text that is comfortable for the user to read.
A good rule is:
Keep data in standard internal units. Format it only when displaying it.
For example, keep altitude and distance in meters, and keep latitude and longitude in radians. When you need to show those values in a panel, log, label, or report, use the appropriate formatting helper.
These functions may apply user preferences, readable units, hemisphere letters, degree symbols, spacing, or other presentation details.
Common display formatting pages include:
Use display formatting for human-facing output only.
Do not use these functions to save structured data in text files. Their output is optimized for readability, not for parsing.
Text translation
Translation helpers let your add-on display labels and messages in the user’s language.
Use them for interface text, buttons, labels, messages, and other text that should be localized.
Examples:
Export formatting
Export formatting functions are for text that may be read back later by Tacview, another program, or your own add-on.
They use stable units and predictable notation. They avoid user-specific display choices that would make exported data harder to parse.
For example, an altitude exported to a CSV file should remain a simple value in meters, not a localized string with the user's preferred unit suffix. In the same spirit, exported angles use clear degree values with documented conventions, so the file remains understandable to both people and tools.
Export formatting is not meant to preserve every internal bit of precision. It is meant to write practical, stable values with enough resolution for reliable playback, analysis, and data exchange, while keeping files reasonably compact.
Use export formatting for CSV files, telemetry export, saved add-on data, and other structured text output.
Common export formatting pages include:
Choosing the right tool
Use the simplest rule:
Use display formatting when a human will read the value directly.
Use export formatting when a value is written to a file or may need to be read back later.
Use
FormatString()to assemble messages from already formatted values.
This keeps add-ons easier to write, easier to localize, and safer to maintain.
Last updated
