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!

How do you display only a certain part of a text string?

Status
Not open for further replies.

sjf

Technical User
Jan 1, 2001
56
AU
I have the situation where I am reading a large selection of text from a memo field in a database. I would like to display say, 60% of this text and have a hyperlink "Click here for more" which links to a page that shows the entire article.

I can do this using the MID function, which simply cuts off at a specified number of characters, which is a satisfactory solution unless the cutoff point is the middle of a word.

Therefore, is it possible to search through a text string and find the next space after a certain number of characters?

Cheers

sjf
 
How about this: just top off my head.

String "12345 67890 9876"
There are three cases:
1. Your sub string ends at the last character of the word.
2. Your sub string ends at the middle of the word.
3. Your sub string ends at the first character of the word.

All you need is the whole or part of the next word.
1. Let say your sub-string is s1="12345" then s2=" 67890 9876", then you can use split(s2, " ", 2) to get the first word of s2, that is empty, then add to s1. --> s1 = "12345"

2. Let say your sub-string is s1="12345 67" then s2="890 9876", then you can use split(s2, " ", 2) to get the first word of s2, that is "890", then add to s2. --> s1 = "12345 67890".

3. Let say your sub-string is s1="12345 " then s2="67890 9876", then you can use split(s2, " ", 2) to get the first word of s2, that is "67890", then add to s2. --> s1 = "12345 67890".

Or you can use your own function instead of split().
Please let me know if it works for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top