String: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (no size limitations)
(extended description)
Line 1: Line 1:
'''Description:'''
== Description ==
ASCII string, e.g. "My name is Victor Troska"


Strings are written enclosed in double quotes, like "Hello".
A string is the [[:Category:Types|variable type]] that can contain text.


You can make a string out of any type by using [[format]].
A string may consist of any number of ASCII characters and is enclosed by single-quotes (only in ArmA) or double-quotes. In OFP, strings could alternatively also be written enclosed by curled braces, which are reserved for [[Code]] in ArmA.


If nested quotes are needed (quotes within quotes) they have to be doubled:<br>
'''Examples (OFP):'''
<code>hint format["My name is ""%1""",name player]</code>


Strings don't seem to have any limitation in size in Armed Assault.
<code>_string = "here is my string"
_string2 = {It may contain a lot of characters #@$}</code>


'''Examples (ArmA):'''


'''Compatibility Notes:'''
<code>_string = "here is my string"
_string2 = 'It may contain a lot of characters #@$'</code>


'''Armed Assault''' and '''Elite'''
If you want to include double quotes (") in strings enclosed by double quotes, the inside double quotes have to be written twice.


Since Armed Assault/Elite, strings can also be alternatively enclosed in apostrophes, like 'Hello'.
<code>_string = "my string ""with"" quotes"
_string2 = 'my other string "with" quotes'</code>


Before ArmA, strings could be enclosed in curled braces, as there was no difference between strings and code.
== Operators ==


In ArmA [[Code|code]] needs to be distinguished clearly, strings can no longer use { } syntax.
The only basic operator to be used on strings is "plus". You can use "plus" to concatenate two strings.


Note: Config strings use very similar syntax, but using quotes is optional.
<code>_string = "Hello " + "world"</code>
 
== Commands ==
 
You can convert any type to a string using the command [[format]]. You can also use that command to build together a string out of different elements. See the documentation of [[format]] for a closer description.
 
<code>_string = [[format]] ["%1", ["my","array","of","strings"]]
hint _string
 
=> ["my","array","of","strings"]</code>
 
== Limitations ==
 
Since ArmA strings don't seem to have any limitation in size.
 
In OFP strings could consist of ??? characters at maximum. Otherwise the game would crash.


[[Category: Types]]
[[Category: Types]]

Revision as of 00:49, 10 December 2006

Description

A string is the variable type that can contain text.

A string may consist of any number of ASCII characters and is enclosed by single-quotes (only in ArmA) or double-quotes. In OFP, strings could alternatively also be written enclosed by curled braces, which are reserved for Code in ArmA.

Examples (OFP):

_string = "here is my string" _string2 = {It may contain a lot of characters #@$}

Examples (ArmA):

_string = "here is my string" _string2 = 'It may contain a lot of characters #@$'

If you want to include double quotes (") in strings enclosed by double quotes, the inside double quotes have to be written twice.

_string = "my string ""with"" quotes" _string2 = 'my other string "with" quotes'

Operators

The only basic operator to be used on strings is "plus". You can use "plus" to concatenate two strings.

_string = "Hello " + "world"

Commands

You can convert any type to a string using the command format. You can also use that command to build together a string out of different elements. See the documentation of format for a closer description.

_string = format ["%1", ["my","array","of","strings"]] hint _string

=> ["my","array","of","strings"]

Limitations

Since ArmA strings don't seem to have any limitation in size.

In OFP strings could consist of ??? characters at maximum. Otherwise the game would crash.