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

Escaping Format Specifiers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Aderic
Senior Member
Join Date: Oct 2011
Old 10-25-2014 , 22:04   Escaping Format Specifiers
Reply With Quote #1

Is there a method to escape format specifiers such as %i, %s, %f, etc?

I could iterate through the string and remove format specifiers from the user input but I'd prefer a method that allowed the input, but treated it as a regular string rather than a placeholder.
__________________

Last edited by Aderic; 10-25-2014 at 22:04.
Aderic is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-25-2014 , 22:22   Re: Escaping Format Specifiers
Reply With Quote #2

Any particular reason you need to do this?

If you pass a string to format for a %s modifier, it won't process any modifiers in it.

i.e.
Code:
Format(myString, sizeof(myString), "%s", userInput);
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Aderic
Senior Member
Join Date: Oct 2011
Old 10-25-2014 , 23:34   Re: Escaping Format Specifiers
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
Any particular reason you need to do this?

If you pass a string to format for a %s modifier, it won't process any modifiers in it.

i.e.
Code:
Format(myString, sizeof(myString), "%s", userInput);
I'll try that out, PrintToChat definitely doesn't honor this system. Doing this:

Code:
PrintToChat(client, "%s", message);
while message contains a %s causes the message to be cut off with an error hitting the client console:
Bad format string in CLocalizeStringTable::ConstructString

Edit: Format is not doing it, I think it has to do with PrintToChat.
Edit 2: I can see two % signs can be used to escape a single % sign, too bad the solution isn't as simple as using %%s to escape %s.
__________________

Last edited by Aderic; 10-26-2014 at 00:10.
Aderic is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 10-26-2014 , 05:13   Re: Escaping Format Specifiers
Reply With Quote #4

%%
Leonardo is offline
Aderic
Senior Member
Join Date: Oct 2011
Old 10-26-2014 , 07:16   Re: Escaping Format Specifiers
Reply With Quote #5

Quote:
Originally Posted by Leonardo View Post
%%
That does not work for escaping %s. That only works for escaping a single % see the posting I made some time ago.
__________________
Aderic is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 10-26-2014 , 07:17   Re: Escaping Format Specifiers
Reply With Quote #6

Quote:
Originally Posted by Aderic View Post
That does not work for escaping %s. That only works for escaping a single % see the posting I made some time ago.
so %%s wont work?

EDIT:
also, built-in chat processor would replace a single % (0x25) with space (0x20).
__________________

Last edited by Leonardo; 10-26-2014 at 10:18.
Leonardo is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 10-26-2014 , 07:56   Re: Escaping Format Specifiers
Reply With Quote #7

Not tested, but what about?
Code:
\%s

Last edited by KissLick; 10-26-2014 at 07:56.
KissLick is offline
Reply



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 15:56.


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