Jump to content

Question about ignoring partial Text Box Imput


Lunar Tripsa
 Share

You are about to reply to a thread that has been inactive for 2190 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello,

I'm trying to decide what direction to take with a project.  Ideally I'd like the user to type something into a text box, then have the script ignore everything but the first word.  I have no idea how to do that though since I won't know how many letters the first word will have.

 

Any help would be great, Thanks!

Link to comment
Share on other sites


Rolig Loon wrote:

Look for the first space? 

integer idx = llSubStringIndex(message, " ");

string FirstWord = llGetSubString(message,0,idx);

One caveat about that bit of code.  If your user decdies for whatever reason (including accidently) adds 1 or more spaces at the beginning, that routine will fail.   The index of the first space will be zero so you will get a substring of  zero to zero....which is nothing.  You need to validate the entry if you have not already thought about it.

messge = llStringTrim(message, STRING_TRIM_HEAD);

//this will strip out all the white spaces at the beginning of the string

// then (and if you want to save a variable)

string firstWord = llGetSubString(message, 0, llSubstringIndex(message, " "));

 

 

 

Link to comment
Share on other sites

Well, if you want to start thinking about all of the things that can go wrong, you should also include the unwanted RETURN when someone hits a keyboard Enter instead of the Submit button.  See http://wiki.secondlife.com/wiki/LlTextBox#Examples .

When you start thinking of ways a user can mess up your ideal design, you can get a real headache.  :smileywink:

Link to comment
Share on other sites

That is true enough.  I agree that trying to anticpate all the ways a user can mess things up is an exercize in insanity.  But we can try to anticpate the more obviouse ones -- the more common ones -- and take some proactive steps to take them into account. 

As in your exmaple I have found that a simple trimming on both ends of the users input  ( msg = llStringTrim(msg, STRING_TRIM); ) will take care of most things.   It will remove  the errant spaces at the beginning as well  will removing any extra spaces at end of the user input along with  the unwanted RETURN. 

In this case, I do think that my input was constructive rather than nitpicky.  Though in retrospect I should probably have done just a simple "trim all" in my example, but the original question was about securing just the first word with anything else on the line dropped onto the floor.  I try, though, to point to the tools at hand let people explore further if they are curious to know more.  :)

Link to comment
Share on other sites

Your answer wasn't nitpicky at all.  It was sound advice.  It's hard to know how much detail to offer in response to a question here.  Sometimes the bare minimum is just what the OP needs, but it never hurts to offer more.  Since you opened the door, I added my flippant reply about all the other things that the OP might consider to encourage him to keep thinking of other things that might go wrong.  ;)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2190 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...