|
-
May 5th, 2005, 07:05 AM
#1
Thread Starter
New Member
SELECT Some words in a field!Please Help
Hi All,
can anyone help me to select the first five words in a field of a table?
Because i want these five words so that i can make it as a link.
any hand will be very apreciated!.
Minh Anh.
-
May 5th, 2005, 07:39 AM
#2
Re: SELECT Some words in a field!Please Help
What if the field has just one word? What front end language are you using? I'd suggest you use a front end language to parse the entire string you receive, since front-end languages usually have better string manipulation functions than (T?)SQL
-
May 5th, 2005, 10:45 PM
#3
Thread Starter
New Member
Re: SELECT Some words in a field!Please Help
I use ASP.NET,and i want the words i get will be the link in the datagrid.Please help me
Minh Anh.
-
May 6th, 2005, 06:00 AM
#4
Frenzied Member
Re: SELECT Some words in a field!Please Help
I dont know the code but Im thinkng you could do someting along the lines of-
Store the text to a variable
Set a count = 0
Set 5 variables one for each word
Use a Loop and the Right function to move accross the text by one while and add to the count one each time while the value is not ="". Whilst looping through the characters build up the word in the first variable. On breaking the loop you will have stored in the count the current position. from there you will know the start postition of the second word. You could then peapat this for all five words by adding a second loop around the first which counts to five. An array may make it easier.
Someone else will know a better way but just thought id have a stab at it.
Ps this assumes you use codebehind such as vb.net although I think it can be done this way in T-SQL Also
Last edited by FishGuy; May 6th, 2005 at 06:01 AM.
Reason: added detail
-
May 6th, 2005, 08:12 AM
#5
Frenzied Member
Re: SELECT Some words in a field!Please Help
This works if you can get your text into a variable.
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim TheSentence As String
TheSentence = "The red rabbit ran round the ragged rock2"
Dim Word1 As String
Dim Word2 As String
Dim Word3 As String
Dim strLen As Integer = Len(TheSentence)
TheSentence.IndexOf(" ")
Word1 = Left(TheSentence, TheSentence.IndexOf(" "))
Label1.Text = Word1
TheSentence = TheSentence.Remove(0, TheSentence.IndexOf(" "))
TheSentence = LTrim(TheSentence)
Word2 = Left(TheSentence, TheSentence.IndexOf(" "))
Label2.Text = Word2
TheSentence = TheSentence.Remove(0, TheSentence.IndexOf(" "))
TheSentence = LTrim(TheSentence)
Word3 = Left(TheSentence, TheSentence.IndexOf(" "))
Label3.Text = Word3
TheSentence = TheSentence.Remove(0, TheSentence.IndexOf(" "))
TheSentence = LTrim(TheSentence)
Label4.Text = Word1 & Word2 & Word3
End Sub
You could even use a loop to replace repeating someof the code
-
May 6th, 2005, 09:26 AM
#6
Re: SELECT Some words in a field!Please Help
How about:
VB Code:
Dim TheSentence As String = "The red rabbit ran round the ragged rock2"
Dim sWords() As String = System.Text.RegularExpressions.Regex.Split(TheSentence, " ")
For i As int16 = 0 to 4
Label1.Text &= sWord(i)
Next
Last edited by wild_bill; May 6th, 2005 at 04:37 PM.
-
May 6th, 2005, 09:48 AM
#7
Frenzied Member
Re: SELECT Some words in a field!Please Help
Some sort of condition would need to be added to just get the first 5 words.
-
May 6th, 2005, 10:33 PM
#8
Thread Starter
New Member
Re: SELECT Some words in a field!Please Help?Solved
Hi Mendhak,Wild Bill,FishGuy!.
My Problem has been solved.thank you very for your help!.
Minh Anh.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|