Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split string based on number off caracters 1

Status
Not open for further replies.

Herminio

Technical User
May 10, 2002
189
PT
I have a table on my DB where the users can post their opinion about my site, and i want to do something like the thing we see here at Tek-tips(member feedback form), but there's a problem i need the number of caracters displayed to be dynamic too, if the string as 50 caracters(for example) i want to display it all, but if it as more i want to display the middle 50, can you guys help me on this?

Herminio, Portugal
 
This will show the first 50 characters of the 'Message' from your recordset

Code:
strMessage = Left(objRS("Message"),50)
Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
oops - my mistake.

Code:
strMessage = objRS("Message") 'original message
intLength = Len(strMessage) 'total length of message
intMidLength = CInt(intLength) 'midpoint of message

strMessage = Mid(strMessage, intMidLength-25, 50) 'middle 50 characters

intMidLength-25 will be the beginning of the middle 50 characters of your message Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Sorry Tony, but there's a bug in your code : if strMessage's len is lower than 25, an error will be raised by
Code:
strMessage = Mid(strMessage,
intLength-25
Code:
, 50)

What i sugest :
Code:
strMessage = "Message" 'original message
intLength = Len(strMessage) 'total length of message

if intLength >50 then
  Dim LeadAndTrailLen 'number of cars to remove from 
                    'beginning and end of the string

  LeadAndTrailLen = CInt((intLength-50) / 2)
  strMessage = Mid(strMessage, LeadAndTrailLen, 50) 'middle 50 characters
End if
Water is not bad as soon as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top