文字列:文字列右から指定文字数取得(Right 関数,RightB 関数)
Right 関数・RightB 関数 の使い方
result_right = Right ( string, length )
result_rightb = RightB ( string, length )
引数・戻り値
- string ・・・ 任意の文字列・文字列式を指定します。
- length ・・・ 取得する文字の長さ(0 以上の整数値)を指定します。
- result_right ・・・ 引数 string の右端から length文字分を取得した文字列(文字列型:String)。
- result_rightb ・・・ 引数 string の右端から lengthバイト分を取得した文字列(文字列型:String)。
引数 string が、Null 値 を含む場合は、Null 値 を返します
引数 length に、0 を指定した場合は、長さ 0 の文字列 (“”) を返します。また、string の文字数以上の値を指定した場合は、string 全体を返します。
Right 関数・RightB 関数 の使用例
サンプルVBAソース
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Sub Sample_Right() Dim myStr As String myStr = "あいうえお。abc def,ghi!" Debug.Print Right(myStr, 16) '右から16文字取得 Debug.Print RightB(myStr, 16) '右から16バイト取得 Debug.Print Right(myStr, 2) '右から2文字取得 Debug.Print RightB(myStr, 2) '右から2バイト取得 Debug.Print Right(myStr, 40) '右から40文字取得(文字数以上を指定) Debug.Print RightB(myStr, 40) '右から40バイト取得(バイト数以上を指定) Debug.Print Right(myStr, 0) '右から0文字取得 Debug.Print RightB(myStr, 0) '右から0バイト取得 End Sub |
実行結果
関連記事
-
-
色の設定(ThemeColor プロパティ・TintAndShade プロパティ)
ThemeColor プロパティ・TintAndShade プロパティ テーマカ …
-
-
日付時刻:日付から曜日を取得( Weekday 関数、WeekdayName 関数 )
Weekday 関数(日付から曜日を表す数値を返す)の使い方 【書式】 week …
-
-
日付時刻:時・分・秒を取得(Hour、Minute、Second 関数)
日付時刻から時・分・秒を取得する関数 【書式】 time_hour = Hour …
-
-
データ型を調べて、そのデータ型を示す数値を返す(VarType 関数)
VarType 関数 の使い方 VarType 関数は、引数に、データ型を調べた …
-
-
インプットボックスを表示する(InputBox関数・InputBoxメソッド)
「InputBox関数」と「InputBoxメソッド」の違い 「InputBox …
-
-
日付時刻:経過時間を取得( Timer 関数 )
Timer 関数の使い方 【書式】 result = Timer () 【戻り値 …
-
-
変数が配列かどうかをチェックする( IsArray 関数 )
IsArray 関数の使い方 【書式】 result = IsArray( va …
-
-
日付時刻:数値から日付・時刻データを取得( DateSerial 関数、TimeSerial 関数 )
DateSerial 関数(数値を使って日付データを取得) 【書式】 date …
-
-
VBA の演算子(比較演算子)
比較演算子 比較演算子による演算の結果は「真」の場合は「True」、「偽」の場合 …
-
-
日付時刻:日付・時刻の間隔を取得( DateDiff 関数 )
DateDiff 関数の使い方 【書式】 result = DateDiff ( …
