FreeBASIC マニュアルのトップに戻る

FreeBASIC STR

目次→言語リファレンス→変数とデータ型→データ型を変換STR←オリジナル・サイト
目次→実行時ライブラリー参考→文字列関数STR←オリジナル・サイト

STR 左にメニュー・フレームが表示されていない場合は、ここをクリックして下さい


数、ブール値、ユニコード文字列の、文字列表現を返します。

構文:
declare function Str ( byval n as byte ) as string
declare function Str ( byval n as ubyte ) as string
declare function Str ( byval n as short ) as string
declare function Str ( byval n as ushort ) as string
declare function Str ( byval n as long ) as string
declare function Str ( byval n as ulong ) as string
declare function Str ( byval n as longint ) as string
declare function Str ( byval n as ulongint ) as string
declare function Str ( byval n as single ) as string
declare function Str ( byval n as double ) as string
declare function Str ( byval b as boolean ) as string
declare function Str ( byref str as const string ) as string
declare function Str ( byval str as const wstring ) as string

用法:
result = Str[$]( number )
または
result = Str( string )

パラメタ:
number
文字列に変換する、数値表現。
string
文字列に変換する、文字列表現。

記述:
Str は、数値変数を、文字列表現に変換します。
これを使うと、数値型変数に適用する Wstr にあたる String を取得できます。
これは、文字列を数値に変換する Val 関数の反対にあたります。

Str は、ブール変数を、その文字列表現 "false" / "true" に変換します。

また、Str は、ユニコード文字列を ASCII 文字列に変換します。
これは、Wstr の正反対をする用法として使われます。
ASCII 文字列を与えると、そのままの変更されていない文字列を返します。

例:
Dim a As Integer
Dim b As String
a = 8421
b = Str(a)
Print a, b
Sleep




 これは Str と WStr の使い分けの例です。
'Str&WStr.bas

'Unicode対応 文字コード表
'http://ash.jp/code/unitbl21.htm

Print "漢",                         Asc("漢")      & Asc("漢",2), Hex(Asc("漢"))      & Hex(Asc("漢",2))
Print "Str(""漢""): "  & Str("漢"), Asc(Str("漢")) & Asc("漢",2), Hex(Asc(Str("漢"))) & Hex(Asc(Str("漢"),2))
Print "WStr(""漢""): " & WStr("漢"), "u" & Asc(WStr("漢")), "u" & Hex(Asc(WStr("漢")))
Print "WStr(""字""): " & WStr("字"), "u" & Asc(WStr("字")), "u" & Hex(Asc(WStr("字")))


Dim ff As UByte

ff = FreeFile
Open "testASCII.txt" For Output As #ff
Print #ff, "漢"
Print #ff, "Str(""漢""): " & Str("漢")
Print #ff, "WStr(""漢""): " & WStr("漢")

Close #ff

ff = FreeFile
Open "testUTF16.txt" For Output Encoding "utf-16" As #ff
Print #ff, "漢"
Print #ff, "Str(""漢""): " & Str("漢")
Print #ff, "WStr(""漢""): " & WStr("漢")

Close #ff

Sleep


方言差:
プラットホーム差:
QBからの違い:
参照:
データ型を変換 に戻る
文字列関数 に戻る

←リンク元に戻る プログラム開発関連に戻る

ページ歴史:2020-09-12 02:37:36
日本語翻訳:WATANABE Makoto、原文著作者:SysOp

ホームページのトップに戻る

表示-非営利-継承