Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Get one word from a string
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Get one word from a string

 Post Reply Post Reply
Author
bootcom View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
Post Options Post Options   Thanks (0) Thanks(0)   Quote bootcom Quote  Post ReplyReply Direct Link To This Post Topic: Get one word from a string
    Posted: 11 April 2005 at 7:06pm

Hi,

I'm in the middle of creating my chat mod for the forums and have come across an issue. One of the commands I will be implementing on there looks as follows: /ban username banlength message_to_user , the user then clicks their send button and the script reads in "/ban" using the following code:
 

 
msg = request.form("strMessageInput")
 
' If the user enters the ban emote then do the ban stuff
If left(lcase(msg), 4) = "/ban" then
 
' If the user is not an administrator then show them an error
If NOT blnAdmin then
 
''''  Error stuff goes in here  '''''
 
Else
 
' This is the main bit where I want to disect the message
 
End If
 
' Put the rest of the checks in below
ElseIf left(lcase(msg), 5) = "/kick" then
End If
 
What I want to do from here is create 3 variables 1 to hold the user name of the user to ban and the next to hold the ban length and the final one to hold the message to the user.
 
What I would like is to ask the question to see if anyone can come up with an easier way to do it than I currently have it planned, as below.
 

' Take the emote out of the string
msg = replace(lcase(msg), "/ban", "")
 
' Trim the string to get rid of all spaces at either end if any exist
msg = trim(msg)
 
' Convert the remaining bit of the message into an array
msgArray = split(msg, " ")
 
' The first part we need to take out is the username to check
banUsername = msgArray(0)
 
' Get the length of the ban we are wishing to give the user
banLength = cInt(msgArray(1))
 
' Get the message to send the user when they are being kicked from the chat
banMsg = msgArray(2)
 
The only problems I have is that from within the 4 part string, 2 of these will be optional - the ban length and the message to the user. So when I run this code and I just enter /ban bootcom the script will spit it out because it is quite clearly no longer an array as there are no spaces to trim. How would I be able to get around this and would anyone have any better suggestions on how to make this work?
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2005 at 7:59pm
using the array is probbabby the best way to do so.. what you could do to over come a sub script error

is when submitted do a javascript that checks the lengh and message fields if they = ""

make then have a miscalanious value like //11\\

then when split its ok.. and after banlengh and blnMSG are set .. from the array chheck if they = //11\\ if so its a no message or legh value

//11\\ = a null value , that is what you are using it for.
Back to Top
bootcom View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
Post Options Post Options   Thanks (0) Thanks(0)   Quote bootcom Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2005 at 8:30pm
Thanks for the advise dj air, Smile
 
I could do it like that but the there's so many commands that can be entered that I don't want to have to check each one with javascript when the form is submitted. I would much rather do it in ASP while I'm doing the other checks. I suppose I could put an extra line in there so when I do the:
 

msg = replace(lcase(msg), "/ban", "")
msg = trim(msg)
 
Then I could also do the following check:
 

if inStr(msg, " ") <> 0 then
' do the create array stuff here
else
' If there is no spaces this means that we just have the user name to deal with
end if
 
Just thought of that one, whats your opinion there?  Or would you think that the JS way is the correct way to proceed?
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 12 April 2005 at 5:34am
i had another think at 2 thismoring...


what you can do is after trim do

if Right(msg,4) = "/ban"

then its not got anything else

but if its not that.. there is something else within the string
Back to Top
Lofty View Drop Down
Newbie
Newbie
Avatar

Joined: 03 April 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote Lofty Quote  Post ReplyReply Direct Link To This Post Posted: 12 April 2005 at 8:22am
I think you'd be best off putting a set devider charater into the command.

split on the devider charater.
replace any /ban


run the array through a loop to count the variables and run each variable through the trim function.

Array = Split(form, "devider character")

counter = 0
For each value in Array
  counter = counter + 1
  If counter = 1 then Username = trim(value)
  If counter = 2 then Bantime = trim(value)
  If counter = 3 then banmessage = trim(value)
Next




Edited by Lofty - 12 April 2005 at 8:54am
Back to Top
bootcom View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
Post Options Post Options   Thanks (0) Thanks(0)   Quote bootcom Quote  Post ReplyReply Direct Link To This Post Posted: 12 April 2005 at 10:45am
Thanks dj air and lofty for your suggestions. I have a better idea on what i'm going to do now. I think I was mainly looking to bounce ideas off you guys and see what you thought, and I was on the right track with what I initially thought, but your ideas will help me improve it.
 
Once again, thanks guys Thumbs Up
 
Much appreciatedClap
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.