?
Solved

Pulling sentences from text string

Posted on 2006-05-25
2
Medium Priority
?
254 Views
Last Modified: 2010-05-18
Is there a more compact way to get the first 3 sentences (if there are 3 sentences - some have less) from a paragraph of text?

                                                               strMessage = RemoveHTML(rsData("Message"))
                        nPos1 = InStr(strMessage, ".")
                        nPos2 = InStr(nPos1 + 1, strMessage, ".")
                        nPos3 = InStr(nPos2 + 1, strMessage, ".")

                        if nPos1 > 0 then
                             strMessage1 = Mid(strMessage, 1, nPos1)
                        end if
                        if nPos2 > nPos1 + 1 then
                              strMessage1 = Mid(strMessage, nPos1 + 1, nPos2 - nPos1)
                        end if
                        if nPos3 > nPos2 + 1 then
                              strMessage1 = Mid(strMessage, nPos2 + 1, nPos3 - nPos2)
                        end if
                        if strMessage1 <> "" then
                              strMessage = strMessage1
                        end if
0
Comment
Question by:ksg313
  • 2
2 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 1000 total points
ID: 16762795
ksg313,

There may be problems with this but you could try to use the Split command (http://www.w3schools.com/vbscript/func_split.asp).  I would think that any problems the command would have would also happen in the code you are using now.  The split command will take a string and use a delimiter you specify (also a string) to create an array.  If you don't want the information in an array then the Split command would not work but I don't see why that would be a problem.  The split command can also take a count argument so that you can stop it after 3.  The code below should do what you want.

   arSentences = Split(strMessage, ". ", 3)

I entered a space in the delimiter so that it would use that and not put it in the strings in the array.  If the sentences use 2 spaces then you could add another in the delimiter setting.  Another option would be to just use the period as the delimiter but then trim leading and trailing spaces.

Let me know if you have questions or need more information.

b0lsc0tt
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16763261
I'm glad that I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question