473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Extracting text from a string

Hi,
I am using VB6 and want to extract text from a string. But ONLY take out
words that begin with 't' or 'd'. The mainstring is input by the user into
'txtMain' and then by clicking a command button, all the words that begin
with 't' or 'd' will be extracted and appear in a second text box,
txtExtract.

So, i know that I have to search through the main string for the character
"d", then extract the following characters until it reaches " " (the space).
I know I will have to use the Mid function to find it and the Len function
to get extract the whole word. The loop it to do the whole string. In
theory it works, but in practice I cant seem to get it to do what I want!
If for example, I type in "dog", the program extracts "d" into the text box,
not the whole word.

Can anyone give me some advice please?

Thanks

Cassandra


Jul 17 '05 #1
1 10413
Hi,

I'd suggest to split the words using the "Split" function and then look for
the first letter.

Here's the code:

--------

Option Explicit
Option Base 0

Private Sub Command1_Click()

Dim words() As String 'array of words
words = Split(txtMain.Text, " ") 'puts every word in the array

Dim i As Integer
For i = 0 To UBound(words) 'passes through the array
If Left(words(i), 1) = "t" Or Left(words(i), 1) = "d" Then
If Len(txtExtract.Text) = 0 Then 'adds the proper words into the
second textbox, delimiting them with spaces
txtExtract.Text = words(i)
Else
txtExtract.Text = txtExtract.Text & " " & words(i)
End If
End If
Next i

End Sub
--------

-- germol

"cassandra.flowers" <ca***************@btopenworld.com> a écrit dans le
message de news:bp**********@titan.btinternet.com...
Hi,
I am using VB6 and want to extract text from a string. But ONLY take out
words that begin with 't' or 'd'. The mainstring is input by the user into 'txtMain' and then by clicking a command button, all the words that begin
with 't' or 'd' will be extracted and appear in a second text box,
txtExtract.

So, i know that I have to search through the main string for the character
"d", then extract the following characters until it reaches " " (the space). I know I will have to use the Mid function to find it and the Len function
to get extract the whole word. The loop it to do the whole string. In
theory it works, but in practice I cant seem to get it to do what I want!
If for example, I type in "dog", the program extracts "d" into the text box, not the whole word.

Can anyone give me some advice please?

Thanks

Cassandra

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lecichy | last post by:
Hello Heres the situation: I got a file with lines like: name:second_name:somenumber:otherinfo etc with different values between colons ( just like passwd file) What I want is to extract...
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
0
by: Mico | last post by:
I would be very grateful for any help with the following: I currently have the code below. This opens a MS Word document, and uses C#'s internal regular expressions library to find if there is a...
7
by: Tempo | last post by:
Hello. I am having a little trouble extracting text from a string. The string that I am dealing with is pasted below, and I want to extract the prices that are contained in the string below. Thanks...
6
by: sunil | last post by:
I have a button named Button1, and I wrote an event handler for the OnClick event. protected void Button1_Click(object sender, System.EventArgs e) { this.Response.Redirect("Default.aspx?q=" +...
4
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields...
2
by: VictorTan | last post by:
Hello. I'm new to this forum. Hope that I don't make mistakes in here but if I do, please correct me if there is. Thanks. I also wanted to ask you guys regarding about the following following...
3
by: Clarisa | last post by:
Hello Folks I am working on extracting lines of data in a text file based on the string it contains. This is the text file called info.txt:
4
by: dexter48 | last post by:
Hi I'm searching for a string occurance in a text file. I find the string ok and write the results to a log file. But on the line above is also some information I need. How can i get that. The string...
6
by: geegeegeegee | last post by:
Hi All, I have come across a difficult problem to do with extracting UniCode characters from RTF strings. A detailed description of my problem is below, if anyone could help, it would be much...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.