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.
Printable View
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.
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
I use ASP.NET,and i want the words i get will be the link in the datagrid.Please help me
Minh Anh.
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
This works if you can get your text into a variable.
You could even use a loop to replace repeating someof the codeVB 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
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
Some sort of condition would need to be added to just get the first 5 words.
Hi Mendhak,Wild Bill,FishGuy!.
My Problem has been solved.thank you very for your help!.
Minh Anh.