StringSetLength

Sets a specified length (in characters) for a string.

bool  StringSetLength(
   string&    string_var,      // string
   uint       new_length       // new string length
   );

Parameters

string_var

[in][out]  String, for which a new length in characters should be set.

new_capacity

[in]  Required string length in characters. If new_length is less than the current size, the excessive characters are discarded.

Return Value

In case of successful execution, returns true, otherwise - false. To receive an error code, the GetLastError() function should be called.

Note

TheStringSetLength() function does not change the size of the buffer allocated for a string.

Example:

void OnStart()
  {
//--- define the string
   string text="123456789012345";
   
//--- display a string and its length in the log
   PrintFormat("Before StringSetLength() the string '%s' has a size of %d characters"textStringLen(text));
   
//--- reduce the string size to 10 characters
   StringSetLength(text10);
   
//--- display a string, changed due to StringSetLength() operation, and its new length to the log
   PrintFormat("After StringSetLength() the string is now '%s', and has a size of %d characters"textStringLen(text));
   
   /*
   Result
   Before StringSetLength() the string '123456789012345has a size of 15 characters
   After StringSetLength() the string is now '1234567890', and has a size of 10 characters
   */
  }

See also

StringLen, StringBufferLen, StringReserve StringInit, StringSetCharacter