number of characters in a string

Discuss CSQC related programming.
Post Reply
Nahuel
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

number of characters in a string

Post by Nahuel »

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.
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Re: number of characters in a string

Post by gnounc »

Code: Select all

float(string s) strlen = #114; /* Part of FRIK_FILE, FTE_STRINGS, ZQ_QC_STRINGS*/
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: number of characters in a string

Post by Spike »

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.
Post Reply