Raised This Month: $12 Target: $400
 3% 

% in string text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NeXoU
Junior Member
Join Date: Jan 2014
Location: France
Old 07-21-2015 , 09:12   % in string text
Reply With Quote #1

Hello,

How can i display "%" in text, when i write % in text with Format, % does not appear.

PHP Code:
Format(testsizeof(test), "%d%"Pourcentage); // Don't work
Format(testsizeof(test), "%d\%"Pourcentage); // Don't work 
Thanks in advance
NeXoU is offline
Icetea16
Member
Join Date: Jul 2015
Location: France
Old 07-21-2015 , 09:24   Re: % in string text
Reply With Quote #2

Tien :

PHP Code:
#include <sdktools>

#define pourcent '%'

public Action OnClientPreAdminCheck(int client)
{
    
CreateTimer(5.0timer_TIMER_REPEAT);
}

public 
Action timer(Handle timer)
{
    
PrintToChatAll(" 5 %s"pourcent);

__________________
I'm French, sorry for my bad english...
Icetea16 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 07-21-2015 , 09:27   Re: % in string text
Reply With Quote #3

%%
Miu is offline
NeXoU
Junior Member
Join Date: Jan 2014
Location: France
Old 07-21-2015 , 09:33   Re: % in string text
Reply With Quote #4

Quote:
Originally Posted by Icetea16 View Post
Tien :

PHP Code:
#include <sdktools>

#define pourcent '%'

public Action OnClientPreAdminCheck(int client)
{
    
CreateTimer(5.0timer_TIMER_REPEAT);
}

public 
Action timer(Handle timer)
{
    
PrintToChatAll(" 5 %s"pourcent);

--> Don't work

Quote:
Originally Posted by Miu View Post
%%
--> Don't work

It's for Menu & Hud.

Thanks in advance

Last edited by NeXoU; 07-21-2015 at 09:37.
NeXoU is offline
Icetea16
Member
Join Date: Jul 2015
Location: France
Old 07-21-2015 , 09:45   Re: % in string text
Reply With Quote #5

Sa fonctionne

PHP Code:
#include <sdktools>

#pragma newdecls required

#define pourcent '%'

public Action OnClientPreAdminCheck(int client)
{
    
CreateTimer(5.0timerclientTIMER_REPEAT);
}

public 
Action timer(Handle timerany client)
{
    
char sText[64];
    
Format(sTextsizeof(sText), "5 %s"pourcent);
    
PrintToChatAll(sText);
    
    
Menu menu = new Menu(Menu_Test);
    
menu.SetTitle("titre");
    
menu.AddItem(""sText);
    
menu.ExitButton true;
    
menu.Display(client0);
}

public 
int Menu_Test(Menu menuMenuAction actionint clientint item)
{
    if (
action == MenuAction_Select)
    {
        
delete menu;
    }
    else if (
action == MenuAction_End)
    {
        
delete menu;
    }

Screenshot:

http://www.noelshack.com/2015-30-143...7-21-00002.jpg
Attached Images
File Type: jpeg bloggif_55ae4ce39e29d.jpeg (15.8 KB, 156 views)
__________________
I'm French, sorry for my bad english...

Last edited by Icetea16; 07-21-2015 at 09:47.
Icetea16 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 07-21-2015 , 09:52   Re: % in string text
Reply With Quote #6

This was mentioned here many times. The right answer is %%.

Always when the string is formated (Format, FormatEx, PrintTo* functions etc.) it converts %% to %.
So, if you format your string twice, you need to use %%%% - first format output is %% and second format output is %.
KissLick is offline
Icetea16
Member
Join Date: Jul 2015
Location: France
Old 07-21-2015 , 09:55   Re: % in string text
Reply With Quote #7

Ok, good explanation.

I did not know
__________________
I'm French, sorry for my bad english...

Last edited by Icetea16; 07-21-2015 at 09:55.
Icetea16 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-21-2015 , 19:07   Re: % in string text
Reply With Quote #8

Quote:
Originally Posted by KissLick View Post
This was mentioned here many times. The right answer is %%.

Always when the string is formated (Format, FormatEx, PrintTo* functions etc.) it converts %% to %.
So, if you format your string twice, you need to use %%%% - first format output is %% and second format output is %.
No, the answer is to not double-format, as it generally implies massive security bugs.
__________________
asherkin is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-22-2015 , 00:46   Re: % in string text
Reply With Quote #9

Quote:
Originally Posted by asherkin View Post
No, the answer is to not double-format, as it generally implies massive security bugs.
Example? (For my own educational benefit.)
Potato Uno is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-21-2015 , 10:01   Re: % in string text
Reply With Quote #10

If you need to print text that you've already formatted, pass it as a String argument to a format-class function.

For example:

Code:
char myString[32];
Format(myString, sizeof(myString), "%s", "5%");
PrintToChatAll("%s", myString);
This example is really contrived, but there are other reasons to do it. I ended up fixing a bug in colors.inc that was doing double formatting this way.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode