![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
string::resize and string::max_size |
julian_boolean
Member #8,201
January 2007
|
While I'm still on sorta the same subject, the last thing I wanted to do was make a function that can censor input by just replacing it with some kinda symbol like "*" or "#".
For that I'm guessing I should use replace? |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
Yes you would need to use replace, unless you are using this for a password and you are wanting *'s to show up instead of the actually text. Is that what you mean? =-----===-----===-----= |
julian_boolean
Member #8,201
January 2007
|
Unless? It will be used for passwords, is there something else already made for that? |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
There is a different method. Where you are actually drawing the text just a number of *'s related to the size of the text they have entered. Keeping it synchronized with the actually amount in it of course (factoring in backspace and what not). EDIT: If you use replace you will actually be overwriting what is in the string. I thought you might be using this to replace cuss words and such with !@#$%^&*'s. =-----===-----===-----= |
julian_boolean
Member #8,201
January 2007
|
What is this method? Overwriting the input as * works too doesn't it? Well for filtering certain words, I figure that would have to be a seperate function on it's own. |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
Quote: What is this method? Overwriting the input as * works too doesn't it? You can go with this method, but when you get to the point of trying to do something with the password they entered in all you are going to see is "*********" The star's are meant for people around you not to see your password. If you overwrite their password with the actual stars then their password then becomes stars. Everyone's password will be almost the same, just varying lengths of stars. What you want to accomplish is keeping their password in the string, then when it comes time to draw their password to the screen you just draw the number of stars that is equivalent to the number of characters in their password. Type in: zomgtheholyinterents If I'm correct with your method their password will be "********************" instead of "zomgtheholyinterents" Now you can keep your method as long as you have another string to store their actual password and one string to store whats actually being drawn to the screen. My method reduces the number of strings you need. =-----===-----===-----= |
julian_boolean
Member #8,201
January 2007
|
I never actually thought of that.. Damn. Well I guess it doesn't really matter if I use an extra string to do that, it's easier for me anyway since I don't know any other way to go about doing it. |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
Yeah I thought I'd stop you before you ran into that run-time. If you show me a clip of your drawing method I can help you draw it without using another string, but there is nothing wrong in using another string if that's what works for you. =-----===-----===-----= |
julian_boolean
Member #8,201
January 2007
|
Here's what my rough guess at what I think it would look like:
Edit: I noticed that if that even worked, it would be only doing the input for editcensor.. |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
Just remove the replaces and do this...: if(!censored) textout_ex(dbuffer, font, edittext.c_str(), textx, texty, WHITE, -1); else { string censor; for(int i = 0; i < edittext.length(); i++) censor += "*"; textout_ex(dbuffer, font, censor.c_str(), textx, texty, WHITE, -1); }
=-----===-----===-----= |
julian_boolean
Member #8,201
January 2007
|
That seems to work, sorta. When I input the text it will show up as *'s, but every keystroke seems to double the amount. In other words, if I type in "test" the "t" would show up as 1 *, the "e" would show up as 2 *'s, etc. Maybe saying "censor = edittext.length();" or something like that might work.. Trying that now. I was fooling around with it again and now a single keystroke makes it automatically print out an ass load of *'s.. I'm sure the problem is very simple, still picking at it.. |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
Oh I'm sorry, here is the fix: if(!censored) textout_ex(dbuffer, font, edittext.c_str(), textx, texty, WHITE, -1); else { string censor; for(int i = 0; i < edittext.length(); i++) censor += "*"; textout_ex(dbuffer, font, censor.c_str(), textx, texty, WHITE, -1); /* / THIS IS THE FIX / */ //censor.erase(); // EDIT: censor.clear(); } The problem was that censor was not erasing, so it would keep re stacking the edittext onto itself. =-----===-----===-----= |
julian_boolean
Member #8,201
January 2007
|
You are not a man but a god! Hehe that works perfectly, one question though: textout_ex(dbuffer, font, censor.c_str(), textx, texty, WHITE, -1); censor.erase(); censor.clear(); What exactly is the difference between erase and clear? |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
I had to go double check myself after I posted on http://www.cppreference.com Quote: You are not a man but a god! Nah, it's just problems that I've ran into before so I know exactly what was going on. I mean.. yes I am a god. =-----===-----===-----= |
julian_boolean
Member #8,201
January 2007
|
Hehe! I just wanted to thank everyone for helping out me so much, especially Matthew. You've all been great, thanks again! |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
FYI: This forum has a new feature that when the creator of the topic posts you can check a box that says something around the lines of "My question was answered fully" then you give props so people know your question has been answered. But a last post like yours is good too =-----===-----===-----= |
23yrold3yrold
Member #1,134
March 2001
![]() |
Quote:
But a last post like yours is good too No. I demand cookies. PS: That checkbox doesn't appear unless you create the thread with one in the first place. -- |
julian_boolean
Member #8,201
January 2007
|
For future reference, how can I do this (is it the thing that says "Classification"?) Thanks. |
Tobias Dammers
Member #2,604
August 2002
![]() |
if(!censored) textout_ex(dbuffer, font, edittext.c_str(), textx, texty, WHITE, -1); else { string censor('*', edittext.length()); // initialize to a given number of asterisks textout_ex(dbuffer, font, censor.c_str(), textx, texty, WHITE, -1); // no need to clear: censor will clear itself when it goes out of scope, since it's non-static }
--- |
Matthew Dalrymple
Member #7,922
October 2006
![]() |
Quote:
For future reference, how can I do this (is it the thing that says "Classification"?) Thanks. Yeah, normally choose "A question seeking a specific answer." To Tobias: =-----===-----===-----= |
|
1
2
|