StringSetLength

Define para a string um comprimento especificado em caracteres.

bool  StringSetLength(
   string&    string_var,      // string
   uint       new_length       // novo comprimento de string
   );

Parâmetros

string_var

[in][out]  String para a qual qual você deseja especificar um novo comprimento em caracteres.

new_capacity

[in]  Comprimento necessário de string em caracteres. Se o novo tamanho new_length for menor do que o tamanho atual, os caracteres não selecionados serão descartados.

Valor retornado

Se for bem-sucedido, retorna true, caso contrário, false. Para obter o código do erro é preciso chamar a função GetLastError().

Observação

A função StringSetLength() não altera o tamanho do buffer alocado para a string.

Exemplo:

void OnStart()
  {
//--- definimos a string
   string text="123456789012345";
   
//--- exibimos no log a string e seu tamanho
   PrintFormat("Before StringSetLength() the string '%s' has a size of %d characters"textStringLen(text));
   
//--- reduzimos o tamanho da string para 10 caracteres
   StringSetLength(text10);
   
//--- exibimos no log a string alterada como resultado da operação StringSetLength() e seu novo tamanho
   PrintFormat("After StringSetLength() the string is now '%s', and has a size of %d characters"textStringLen(text));
   
  /*
  Resultado
   Before StringSetLength() the string '123456789012345has a size of 15 characters
   After StringSetLength() the string is now '1234567890', and has a size of 10 characters
  */
  }

Veja também

StringLen, StringBufferLen, StringReserve StringInit, StringSetCharacter