Difference between revisions of "Category:LSL String/ja"

From Second Life Wiki
Jump to navigation Jump to search
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Multi-lang}}
{{Multi-lang}}
{{LSL Header/ja}}
{{LSL Header/ja|ml=*}}
<div style="float:right">__TOC__</div>
{{LSLC/ja|}}{{LSLC/ja|Types}}
stringはテキストデータです。stringの長さは、有効な[[script memory/ja|スクリプト容量]]の限界までです。 Stringの値はLSLテキストを定義するときに、ダブルクォーテーション(" ")て囲まれます。いくつかの文字はエスケープされる必要があるだろうけれど、stringで用いることができるでしょう。
{{RightToc}}


stringは'''+'''演算子を用いて結合させることができます。
stringはテキストデータです。stringの長さは、有効な[[Script_memory/ja|スクリプト容量]]の限界までです。 Stringの値はLSLテキストを定義するときに、ダブルクォーテーション(" ")て囲まれます。いくつかの文字はエスケープされる必要があるだろうけれど、stringで用いることができるでしょう。


<div style="float:left">
stringは'''+演算子'''を用いて結合させることができます。
{|{{Prettytable}}
 
|+'''エスケープコード'''
<div id="box">
== Escape Codes==
<div style="padding: 0.5em;">
{|{{Prettytable|style=float:left;}}
|+
|-{{Hl2}}
|-{{Hl2}}
!部分文字
!Substring
!置換されるもの
!Replaced with
|-
|-
|| \t || 4スペース
|| \t || 4スペース
Line 21: Line 25:
|| \\ || バックスラッシュ
|| \\ || バックスラッシュ
|}
|}
</div>
{|
{|
|
|String 例:
String 例:
<source lang="lsl2">"Hello Avatar!"
<pre>"Hello Avatar!"
"Yes"
"Yes"
"No"
"No"
Line 32: Line 34:
"Help " + "me"
"Help " + "me"
EOF
EOF
//The following two strings have the same value.
 
//以下の2つのstringは同じ値です。
 
"I scream,\nyou scream,\nwe all scream,\nfor ice-cream!"
"I scream,\nyou scream,\nwe all scream,\nfor ice-cream!"
"I scream,
"I scream,
Line 38: Line 42:
we all scream,
we all scream,
for ice-cream!"
for ice-cream!"
</pre>
</source>
|}
|}
</div></div>


Note: Escape codes (listed above) are translated when the script is compiled, and not while it's running.
Note: エスケープコード(上記一覧)はスクリプトがコンパイルされるときに翻訳され、動いてる間はされません。 stringはコンパイルされたとき、結果としてスクリプト内部の\nを"改行"文字に変換するでしょう。ノートカード、チャット、httpその他から読み込むテキストはエスケープコードではチェックされませんから、ノートカードでの\n入力は自動で"改行"文字には変換されません。自らしなければなりませんが、本当に本当に必要な場合だけにすべきです。
The result: only strings that are inside your script when it is compiled will get, say, \n turned into a "new line" character.  Text you read in from a notecard, chat, http, etc, will not be checked for escape codes -- that same \n typed in a notecard doesn't automatically turn into a "new line" character in any case.  You'll have to do that yourself, if you really really need it for some reason.


Note: People who come to LSL from C and Java and such languages may find these LSL string escape rules confusing while new. LSL "\n" means llUnescapeURL("%0A"), same as C and Java, but "\t" means llUnescapeURL("%20%20%20%20") rather than llUnescapeURL("%09"), and "\r" means "r" rather than llUnescapeURL("%0D"), etc.
Note: CとJavaや同様な言語からLSLに入った人は、始めたばかりの間はLSL stringのエスケープルールで混乱するでしょう。 LSLの"\n"の意味は{{LSLG/ja|llUnescapeURL}}("%0A")で、CとJavaに似てますが、"\t"の意味は{{LSLG/ja|llUnescapeURL}}("%09")より{{LSLG/ja|llUnescapeURL}}("%20%20%20%20") が最適で、"\r"の意味は{{LSLG/ja|llUnescapeURL}}("%0D")よりも"r"が最適、などなど。


{{#vardefine:p_name_desc|variable name
{{#vardefine:p_name_desc|変数名
}}{{#vardefine:p_value_desc|string expression or constant
}}{{#vardefine:p_value_desc|string 要素もしくは定型値
}}{{#vardefine:p_value_t_desc|expression or constant
}}{{#vardefine:p_value_t_desc|要素もしくは定型値
}}
}}
<div id="box">
<div id="box">
== Variable: string {{LSL Param|name}}; ==
== 変数: string {{LSL Param|name}}; ==
<div style="padding: 0.5em;">
<div style="padding: 0.5em;">
<pre>string name;</pre>
<source lang="lsl2">string name;</source>
Declares a variable of type string named '''name''', with the value {{HoverText|""|empty string}}
宣言するstring型の変数を'''name'''と名づけて、{{HoverText|""|空のstring}}にします。
{|
{|
{{LSL DefineRow|variable|name|{{#var:p_name_desc}}}}
{{LSL DefineRow|variable|name|{{#var:p_name_desc}}}}
Line 61: Line 65:


<div id="box">
<div id="box">
== Variable: string {{LSL Param|name}} {{=}} {{LSL Param|value}}; ==
== 変数: string {{LSL Param|name}} {{=}} {{LSL Param|value}}; ==
<div style="padding: 0.5em;">
<div style="padding: 0.5em;">
<pre>string name = value;</pre>
<source lang="lsl2">string name = value;</source>
Declares a variable of type string named '''name''', with the value '''value'''.
宣言するstring型の変数を'''name'''と名づけて、'''value'''の値をいれます。
{|
{|
{{LSL DefineRow|variable|name|{{#var:p_name_desc}}}}
{{LSL DefineRow|variable|name|{{#var:p_name_desc}}}}
Line 72: Line 76:


<div id="box">
<div id="box">
== [[Typecast]]: (string){{LSL Param|value_t|value}} ==
== [[Typecast/ja|型の変換]]: (string){{LSL Param|value_t|value}} ==
<div style="padding: 0.5em;">
<div style="padding: 0.5em;">
<pre>(string)value</pre>
<source lang="lsl2">(string)value</source>
Converts '''value''' to a value of type string.
'''value'''をstring型の値に変換します。
{|
{|
{{LSL DefineRow|expression|value|{{#var:p_value_t_desc}}}}
{{LSL DefineRow|expression|value|{{#var:p_value_t_desc}}}}
Line 83: Line 87:
<div id="box">
<div id="box">


== [[LSL Operators|Operators]] ==  
== [[LSL Operators/ja|演算子]] ==  
<div style="padding: 0.5em;">
<div style="padding: 0.5em;">
See [[LSL Operators|Operators]] for more information.
ほかの情報は[[LSL Operators/ja|演算子]] を参照します。
<div id="box" style="padding-left: 0.5em;padding-right: 0.5em;padding-bottom: 0.5em;">
<div id="box" style="padding-left: 0.5em;padding-right: 0.5em;padding-bottom: 0.5em;">
=== Combine: {{LSL Param|value|value1}} + {{LSL Param|value|value2}} ===
=== 結合: {{LSL Param|value|value1}} + {{LSL Param|value|value2}} ===
<pre>(value1 + value2)</pre>
<source lang="lsl2">(value1 + value2)</source>
Combines two strings into a single string without modifying the inputs. Appends '''value2''' to '''value1''' and returns the resulting string.
入力での編集以外で、2つのstringを1つのstringに結合します。'''value2''''''value1'''を加えて、結果のstringに返します。
{|
{|
{{LSL DefineRow|expression|value1|{{#var:p_value_desc}}}}
{{LSL DefineRow|expression|value1|{{#var:p_value_desc}}}}
Line 97: Line 101:
<div id="box" style="padding-left: 0.5em;padding-right: 0.5em;padding-bottom: 0.5em;">
<div id="box" style="padding-left: 0.5em;padding-right: 0.5em;padding-bottom: 0.5em;">


=== Comparison: {{LSL Param|value|value1}} <nowiki>==</nowiki> {{LSL Param|value|value2}} ===
=== 比較: {{LSL Param|value|value1}} <nowiki>==</nowiki> {{LSL Param|value|value2}} ===
<pre>(value1 == value2)</pre>
<source lang="lsl2">(value1 == value2)</source>
Compares two strings, returns {{HoverText|one|1}} if same length and same characters, else returns zero.
2つのstringを比較して、同じ長さで同じ文字なら1を返し、そうでなければ0を返します。 この演算子はCの<code>!strcmp('''value1''', '''value2''')</code>と極めて似たような働きをし、従ってCやJavaでの == 演算子と直観的に異なる故に、技術的に異なるものです。
This operator works exactly like <code>!strcmp('''value1''', '''value2''')</code> in C, thus technically differs from the counterintuitive behavior of the == operator in C and in Java.
{|
{|
{{LSL DefineRow|expression|value1|{{#var:p_value_desc}}}}
{{LSL DefineRow|expression|value1|{{#var:p_value_desc}}}}
Line 107: Line 110:
</div>
</div>
<div id="box" style="padding-left: 0.5em;padding-right: 0.5em;padding-bottom: 0.5em;">
<div id="box" style="padding-left: 0.5em;padding-right: 0.5em;padding-bottom: 0.5em;">
=== Comparison: {{LSL Param|value|value1}} != {{LSL Param|value|value2}} ===
=== 比較: {{LSL Param|value|value1}} != {{LSL Param|value|value2}} ===
<pre>(value1 != value2)</pre>
<source lang="lsl2">(value1 != value2)</source>
Compares two strings, returns {{HoverText|zero|0}} if same length and same characters, otherwise non-zero.
2つのstringを比較し、同じ長さで同じ文字であれば{{HoverText|zero|0}}を返し、そうでなければ0ではないものを返します。 この演算子はCの<code>strcmp('''value1''', '''value2''')</code>と極めて似た働きをし、従ってCやJavaでの != 演算子と直観的に異なる故に、技術的に異なるものです。
This operator works exactly like <code>strcmp('''value1''', '''value2''')</code> in C, thus technically differs from the counterintuitive behavior of the != operator in C and in Java.
{|
{|
{{LSL DefineRow|expression|value1|{{#var:p_value_desc}}}}
{{LSL DefineRow|expression|value1|{{#var:p_value_desc}}}}
Line 119: Line 121:


<div id="box">
<div id="box">
 
== ==
== Examples ==
<div style="padding: 0.5em;">
<div style="padding: 0.5em;">
<pre>
<source lang="lsl2">integer int = 48934;
integer int = 48934;
string str = (string)int;
string str = (string)int;
string str_2;
string str_2;
str_2 = str;
str_2 = str;</source>
</pre>
</div></div>
</div></div>
<div id="box">
<div id="box">
== Useful Functions ==
== よく用いる関数 ==
<div style="padding: 0.5em;">
<div style="padding: 0.5em;">
=== String functions in the [[Library_Combined_Library|CombinedLibrary]] ===
=== ユーザが作成したユーティリティ関数 ===
{|
{|{{Prettytable}}
{{LSL DefineRow||[[Library_Combined_Library#str_replace|str_replace]]|replace all instances of a string with another string in a target string.}}
|+
{{LSL DefineRow||[[Library_Combined_Library#Trim|TrimRight]]|Trim characters from the right end of a string}}
|-{{Hl2}}
{{LSL DefineRow||[[Library_Combined_Library#Trim|TrimLeft]]|Trim characters from the left end of a string}}
!関数
{{LSL DefineRow||[[Library_Combined_Library#Trim|TrimBoth]]|Trim characters from the both ends of a string}}
!説明
|-
|| [[Chr]] || Returns the Unicode character with the given code. See also [[Ord]].
|-
|| [[Float2String]] || Allows string output of a float in a tidy text format, with optional rounding.
|-
|| [[Left]] || Returns text left of a specified separator.
|-
|| [[Like]] || See if one word matches part of another.
|-
|| [[Ord]] || Returns the ordinal (Unicode code) of a character. See also [[Chr]].
|-
|| [[RandomString]] || Creates a random string.
|-
|| [[RemoveHTMLTags]] || Removes HTML tags from a string ( and newline characters )
|-
|| [[Right]] || Returns text right of a specified separator.
|-
|| [[Library_Combined_Library#str_replace|str_replace]] || 全ての対象string内の、stringインスタンスとその他のstringを置換します。
|-
|| [[Stristr]] || Returns a string from the first occurrence of needle to the end of haystack.
|-
|| [[SplitLine]] || '改行'エスケープコードをstringの特定の箇所に挿入します。
|-
|| [[Library_Combined_Library#TrimRight|TrimRight]] || stringの右端から文字の余計な空白を削除します。
|-
|| [[Library_Combined_Library#TrimLeft|TrimLeft]] || stringの左端から文字の余計な空白を削除します。
|-
|| [[Library_Combined_Library#TrimBoth|TrimBoth]] || stringの両端から文字の余計な空白を削除します。
|-
|| [[WrapText]] || Break text into line lengths of your specification.
|}
|}
=== Examples ===
 
{|
[[Library_Combined_Library|CombinedLibrary]]のString関数
{{LSL DefineRow||[[Examples|SplitLine]]|Insert 'new line' escape codes at certain positions of a string}}
 
=== スクリプトライブラリ内のテキスト関係のスクリプト ===
{| {{Prettytable}}
|-
|{{Hl2}}| '''スクリプト名'''
|{{Hl2}}| '''製作者'''
|{{Hl2}}| '''説明'''
|-
||[[ParseString2List]]
||[[User:Strife Onizuka|Strife Onizuka]]
||Same as [[llParseString2List]] and [[llParseStringKeepNulls]], but not limited to 8 spacers or separators. Thus substitute a call to the [[llParseString2List]] and [[llParseStringKeepNulls]] functions by a call to [[Parse_String_To_List|ParseString2List]] whenever you have more than 8 separators or more than 8 spacers.
|-
 
||[[String Compare]]
||[[User:Xaviar Czervik|Xaviar Czervik]]
||Compares two strings and reliably returns either 1, -1, or 0 if they are the same.
|-
||[[XyText 1.5|XyText]]
||[[User:Xylor Baysklef|Xylor Baysklef]]
|| Display text (up to 10 characters) on a prim. Use as many prims as desired.
|-
||[[XyyyyzText|XyyyyzText]]
||[[User:Criz Collins|Criz Collins]]
|| Display text (up to 10 characters) on a prim. Displays different text for each line instead of one single text, that will be broken into the next lines. Watch here for what that means: http://screencast.com/t/1wMLujLcEO
|-
||[[XyzzyText|XyzzyText]]
||[[User:Thraxis Epsilon|Thraxis Epsilon]] and [[User:Gigs Taggart|Gigs Taggart]]
|| Display text (up to 10 characters) on a prim. Way more efficient than XyText.
|}
|}
</div></div>
</div>

Revision as of 17:59, 18 December 2015

stringはテキストデータです。stringの長さは、有効なスクリプト容量の限界までです。 Stringの値はLSLテキストを定義するときに、ダブルクォーテーション(" ")て囲まれます。いくつかの文字はエスケープされる必要があるだろうけれど、stringで用いることができるでしょう。

stringは+演算子を用いて結合させることができます。

Escape Codes

Substring Replaced with
\t 4スペース
\n 改行
\" ダブルクオーテーション
\\ バックスラッシュ
String 例:
"Hello Avatar!"
"Yes"
"No"
"It's 10 o'clock."
"I am 21 years old!"
"Help " + "me"
EOF

//以下の2つのstringは同じ値です。

"I scream,\nyou scream,\nwe all scream,\nfor ice-cream!"
"I scream,
you scream,
we all scream,
for ice-cream!"

Note: エスケープコード(上記一覧)はスクリプトがコンパイルされるときに翻訳され、動いてる間はされません。 stringはコンパイルされたとき、結果としてスクリプト内部の\nを"改行"文字に変換するでしょう。ノートカード、チャット、httpその他から読み込むテキストはエスケープコードではチェックされませんから、ノートカードでの\n入力は自動で"改行"文字には変換されません。自らしなければなりませんが、本当に本当に必要な場合だけにすべきです。

Note: CとJavaや同様な言語からLSLに入った人は、始めたばかりの間はLSL stringのエスケープルールで混乱するでしょう。 LSLの"\n"の意味はllUnescapeURL("%0A")で、CとJavaに似てますが、"\t"の意味はllUnescapeURL("%09")よりllUnescapeURL("%20%20%20%20") が最適で、"\r"の意味はllUnescapeURL("%0D")よりも"r"が最適、などなど。


変数: string name;

string name;

宣言するstring型の変数をnameと名づけて、""にします。

• variable name 変数名

変数: string name = value;

string name = value;

宣言するstring型の変数をnameと名づけて、valueの値をいれます。

• variable name 変数名
• expression value string 要素もしくは定型値

型の変換: (string)value

(string)value

valueをstring型の値に変換します。

• expression value 要素もしくは定型値

演算子

ほかの情報は演算子 を参照します。

結合: value1 + value2

(value1 + value2)

入力での編集以外で、2つのstringを1つのstringに結合します。value2value1を加えて、結果のstringに返します。

• expression value1 string 要素もしくは定型値
• expression value2 string 要素もしくは定型値

比較: value1 == value2

(value1 == value2)

2つのstringを比較して、同じ長さで同じ文字なら1を返し、そうでなければ0を返します。 この演算子はCの!strcmp(value1, value2)と極めて似たような働きをし、従ってCやJavaでの == 演算子と直観的に異なる故に、技術的に異なるものです。

• expression value1 string 要素もしくは定型値
• expression value2 string 要素もしくは定型値

比較: value1 != value2

(value1 != value2)

2つのstringを比較し、同じ長さで同じ文字であればzeroを返し、そうでなければ0ではないものを返します。 この演算子はCのstrcmp(value1, value2)と極めて似た働きをし、従ってCやJavaでの != 演算子と直観的に異なる故に、技術的に異なるものです。

• expression value1 string 要素もしくは定型値
• expression value2 string 要素もしくは定型値

integer int = 48934;
string str = (string)int;
string str_2;
str_2 = str;

よく用いる関数

ユーザが作成したユーティリティ関数

関数 説明
Chr Returns the Unicode character with the given code. See also Ord.
Float2String Allows string output of a float in a tidy text format, with optional rounding.
Left Returns text left of a specified separator.
Like See if one word matches part of another.
Ord Returns the ordinal (Unicode code) of a character. See also Chr.
RandomString Creates a random string.
RemoveHTMLTags Removes HTML tags from a string ( and newline characters )
Right Returns text right of a specified separator.
str_replace 全ての対象string内の、stringインスタンスとその他のstringを置換します。
Stristr Returns a string from the first occurrence of needle to the end of haystack.
SplitLine '改行'エスケープコードをstringの特定の箇所に挿入します。
TrimRight stringの右端から文字の余計な空白を削除します。
TrimLeft stringの左端から文字の余計な空白を削除します。
TrimBoth stringの両端から文字の余計な空白を削除します。
WrapText Break text into line lengths of your specification.

CombinedLibraryのString関数

スクリプトライブラリ内のテキスト関係のスクリプト

スクリプト名 製作者 説明
ParseString2List Strife Onizuka Same as llParseString2List and llParseStringKeepNulls, but not limited to 8 spacers or separators. Thus substitute a call to the llParseString2List and llParseStringKeepNulls functions by a call to ParseString2List whenever you have more than 8 separators or more than 8 spacers.
String Compare Xaviar Czervik Compares two strings and reliably returns either 1, -1, or 0 if they are the same.
XyText Xylor Baysklef Display text (up to 10 characters) on a prim. Use as many prims as desired.
XyyyyzText Criz Collins Display text (up to 10 characters) on a prim. Displays different text for each line instead of one single text, that will be broken into the next lines. Watch here for what that means: http://screencast.com/t/1wMLujLcEO
XyzzyText Thraxis Epsilon and Gigs Taggart Display text (up to 10 characters) on a prim. Way more efficient than XyText.