StringSetLength

文字列に指定された長さ(文字数)を設定します。

bool  StringSetLength(
  string&    string_var,      // 文字列
  uint       new_length       // 新しい文字列の長さ
  );

パラメータ

string_var

[in][out]  新しい文字数を設定する文字列

new_capacity

[in]  文字数での必要な文字列の長さ。new_lengthが現在のサイズより小さい場合、余分な文字は破棄されます。

戻り値

実行成功の場合はtrue、それ以外の場合はfalseエラーコードを受け取るには、GetLastError()関数が呼び出されるべきです。

注意事項

StringSetLength()関数は、文字列に割り当てられたバッファのサイズを変更しません。

例:

void OnStart()
 {
//--- 文字列を定義する
  string text="123456789012345";
 
//--- 文字列とその長さをログに表示する
  PrintFormat("Before StringSetLength() the string '%s' has a size of %d characters", text, StringLen(text));
 
//--- 文字列サイズを10文字に減らす
  StringSetLength(text, 10);
 
//--- StringSetLength()操作によって変更された文字列とその新しい長さをログに表示する
  PrintFormat("After StringSetLength() the string is now '%s', and has a size of %d characters", text, StringLen(text));
 
 /*
  結果
  Before StringSetLength() the string '123456789012345' has a size of 15 characters
  After StringSetLength() the string is now '1234567890', and has a size of 10 characters
 */
 }

参照

StringLenStringBufferLenStringReserve、<li6 >StringInit、StringSetCharacter