one more time (Bill)

Results 1 to 7 of 7

Thread: one more time (Bill)

  1. #1
    Mark b. Guest

    Default one more time (Bill)

    Hi. There The first bit of code works. cool it cuts the first part of a string off. but i cant get it working for the end bit.. eg strDesc = "ug. Please leave me alone stu" ok the "ug." bit will be removed but i cant get the " stu" to be removed.<BR><BR> &#039;--find first space<BR> DescPosistion = InStr(strDesc, " ")<BR> &#039;--cut off first word<BR> strDesc = Left(strDesc, (Len(strDesc) - DescPosistion))<BR> &#039;--find last space<BR> &#039;DescLast = InStrRev(strDesc, " ")<BR> &#039;--cut off last word <BR> &#039;strDesc = Right(strDesc, (Len(strDesc) - DescLast))<BR><BR>Please help thanx from Mark

  2. #2
    Join Date
    Dec 1969

    Default RE: one more time (Bill)

    strDesc = "ug. Please leave me alone stu"<BR>&#039;--find first space<BR>DescPosistion = InStr(strDesc, " ")<BR>Response.Write "DescPosistion="&(DescPosistion)&"<BR>"<BR>&#0 39;--cut off first word<BR>strDesc = Left(strDesc, (Len(strDesc) - DescPosistion))<BR>Response.Write "strDesc="&(strDesc)&"<BR>"<BR>strDesc = Right(strDesc, (Len(strDesc) - DescPosistion))<BR>Response.Write "strDesc2="&(strDesc)&"<BR>"

  3. #3
    Join Date
    Dec 1969

    Default You've got it backwards...

    ...and MID works better for getting stuff *past* the first space, anyway...<BR><BR>&#060;%<BR>strDesc = Mid( strDesc, InStr(strDesc," ") + 1 )<BR>strDesc = Left( strDesc, InStrRev(strDesc," ") - 1 )<BR>%&#062;<BR><BR>I think maybe you misunderstood what Left and Right do???<BR><BR>Look at this example and your code:<BR><BR>strDesc="12 4567 890 1234 5678"<BR><BR>Your code:<BR>DescPosistion = InStr(strDesc, " ")<BR>&nbsp; &nbsp; so DescPosistion [sic...misspelled] is 3<BR>strDesc = Left(strDesc, (Len(strDesc) - DescPosistion))<BR>&nbsp; &nbsp; so that becomes Left(strDesc, (18 - 3) )<BR>&nbsp; &nbsp; ...or get the first 15 now you would have<BR>&nbsp; &nbsp; &nbsp; &nbsp; strDesc="12 4567 890 1234 5"<BR><BR>No point in going further. Can you say "oops"?<BR><BR>When something like this gets to you, it&#039;s time to DEBUG DEBUG DEBUG. Lots of Response.Writes.<BR><BR>If you had done<BR><BR>Response.Write DescPosition<BR>Response.Write strDesc &#039; *after* that first LEFT<BR><BR>you&#039;d have seen immediately what you did wrong.<BR><BR>

  4. #4
    Join Date
    Dec 1969

    Default And if you couldn't tell...

    ...Paul wasn&#039;t giving you the answer. He was just showing you how you should DEBUG. Ehhh...maybe I should have done the same.<BR><BR>

  5. #5
    mark.b Guest

    Default RE: You've got it backwards...

    i just wanted to say thanks for the help. normaly i would have done this all myself but my asp book doesn&#039;t have anything on inStr() and mid and all these string functions.. do you know of any good articals.<BR><BR>Once again thanks alot.. if you want to see what i was working on check out this url.<BR> tical<BR><BR>from mark

  6. #6
    Daniel Newman Guest

    Default RE: You've got it backwards...

    So why couldn&#039;t you have just used a simple Replace?<BR><BR>strText, strSearchTerm<BR><BR>Response.Write Replace(strText, strSearchTerm, HighliteText(strSearchTerm))<BR><BR>HighliteText being a custom function that will do your formatting for you<BR><BR>Does that look any simpler?<BR><BR>Daniel Newman.

  7. #7
    xycodex Guest

    Default help

    search the microsoft site for the vbscript documentation.<BR>Better still, go to the 4guysfromrolla main site and look for &#039;technical docs&#039; on the navbar and look at the microsoft links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts