String problem

# Thread: String problem

1. Junior Member
Join Date
Dec 1969
Posts
8

## String problem

I want to display only the first part of a paragraph of text that I retrieve from a database. I know that if you do:<BR><BR>Left(str, n)<BR><BR>it will display only n characters of a string, str, counting from the left. However, I want to make sure that the last word displayed is a full word and not a partial word, punctuation mark (such as an apostrophe), etc. In other words, I don&#039;t want it to look like this:<BR><BR>This is the only part of the string that I wa...<BR><BR>I&#039;d rather it look like this:<BR><BR>This is the only part of the string that I want...<BR><BR>I&#039;d like it to check for a space once it counts n characters from the left of the string and if there&#039;s no space there, to add to n until it encounters a space. Does anyone know of any way to do this?<BR><BR>Thanks!

2. Senior Member
Join Date
Dec 1969
Posts
412

## RE: String problem

use regular expressions<BR><BR>something like "sw+s" will find a word

3. Junior Member
Join Date
Dec 1969
Posts
8

## RE: String problem

That really wouldn&#039;t solve my problem, since Left(str, n) returns all the characters up to the number n. I&#039;m wondering if there&#039;s a way to determine what the final character of Left(str, n) would be, whether it&#039;s a space, an "r", a "d", etc.

4. Senior Member
Join Date
Dec 1969
Posts
2,049

## RE: Try this...

&#060;%<BR>Dim Str<BR>Dim Lstr<BR>Str = "The blue whale dives deep into the oceans depths." &#039;whatever??<BR>i_loop = 22 &#039;starting point.<BR>Do Until Lstr = Chr(32)<BR>Response.Write i_loop &"<BR>"<BR>If i_loop = 28 Then break<BR>Lstr = Mid(Str,i_loop,1)<BR>i_loop = i_loop+1<BR>Loop<BR>%&#062;<BR>&#060;%= Left(Str,i_loop -1) %&#062;<BR><BR>Just an idea.

5. Senior Member
Join Date
Dec 1969
Posts
2,049

## RE: Try this...

Here is the code w/o the testing stuff.<BR><BR>&#060;%<BR>Dim Str<BR>Dim Lstr<BR>Str = "The blue whale dives deep into the oceans depths." &#039;whatever??<BR>i_loop = 22 &#039;char starting point. Make any length.<BR>Do Until Lstr = Chr(32)<BR>Lstr = Mid(Str,i_loop,1)<BR>i_loop = i_loop+1<BR>Loop<BR>%&#062;<BR>&#060;%= Left(Str,i_loop -1) %&#062;<BR><BR>I just found a use for it myself.

#### Posting Permissions

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