number of characters in a string
number of characters in a string
it´s possible to get the number of characters in a string? i need to know how many characters there are in a string (spaces included) to center the string in a specific location in the screen thanks in advance!!
hi, I am nahuel, I love quake and qc.
Re: number of characters in a string
Code: Select all
float(string s) strlen = #114; /* Part of FRIK_FILE, FTE_STRINGS, ZQ_QC_STRINGS*/
Re: number of characters in a string
small note, strlen only works for centering strings when the font is a fixed width. also, it does not understand colour codes so you might want to strip those first.
If you're writing csqc/menu code, the following builtin is a better option, but is not supported in ssqc (where fonts are not known).
float(string text, float usecolours, optional vector fontsize) stringwidth = #327;
Calculates the width of the text in virtual pixels. If usecolours is 1, markup that does not affect the displayed string width will be ignored (so generally pass 1 for that).
If the fontsize is not specified, '8 8 0' will be assumed.
If you're writing csqc/menu code, the following builtin is a better option, but is not supported in ssqc (where fonts are not known).
float(string text, float usecolours, optional vector fontsize) stringwidth = #327;
Calculates the width of the text in virtual pixels. If usecolours is 1, markup that does not affect the displayed string width will be ignored (so generally pass 1 for that).
If the fontsize is not specified, '8 8 0' will be assumed.