Forum

number of characters in a string

Discuss CSQC related programming.

Moderator: InsideQC Admins

number of characters in a string

Postby Nahuel » Sun Feb 02, 2014 4:36 am

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.
User avatar
Nahuel
 
Posts: 492
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: number of characters in a string

Postby gnounc » Sun Feb 02, 2014 5:15 am

Code: Select all
float(string s) strlen = #114; /* Part of FRIK_FILE, FTE_STRINGS, ZQ_QC_STRINGS*/
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: number of characters in a string

Postby Spike » Sun Feb 02, 2014 5:23 pm

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.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to CSQC Programming

Who is online

Users browsing this forum: No registered users and 1 guest