473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: searching through a string and pulling characters

En Mon, 18 Aug 2008 17:40:13 -0300, Alexnb <al********@gmail.comescribió:
Lets say I have a text file. The contents look like this, only there is A
LOT of the same thing.

() A registry mark given by underwriters (as at Lloyd's) to ships in
first-class condition. Inferior grades are indicated by A 2 and A 3.
() The first three letters of the alphabet, used for the whole alphabet.
() In church or chapel style; -- said of compositions sung in the old church
style, without instrumental accompaniment; as, a mass a capella, i. e., a
mass purely vocal.
() Astride; with a part on each side; -- used specif. in designating the
position of an army with the wings separated by some line of demarcation, as
a river or road.

Now, I am talking 1000's of these. I need to do something like this. I will
have a number, and what I want to do is go through this text file, just like
the example. The trick is this, those "()'s" are what I need to match, so if
the number is 245 I need to find the 245th () and then get the all the text
from after it until the next (). If you have an idea about the best way to
do this I would love your help. If you made it all the way through thanks!
;)
pydata = """() A registry mark given by underwriters (as at Lloyd's) to ships in
.... first-class condition. Inferior grades are indicated by A 2 and A 3.
.... () The first three letters of the alphabet, used for the whole alphabet.
.... () In church or chapel style; -- said of compositions sung in the old church
.... style, without instrumental accompaniment; as, a mass acapella, i. e., a
.... mass purely vocal.
.... () Astride; with a part on each side; -- used specif. in designating the
.... position of an army with the wings separated by some line of demarcation, as
.... a river or road.
.... """
py# there is no 0th element, I presume, so I start with an empty one
.... current = []
pychecks = [current]
pyfor line in data.split('\n'):
.... if line[:2]=='()':
.... current = [line[3:]]
.... checks.append(current)
.... else:
.... current.append(line)
....
pyprint checks[3]
['In church or chapel style; -- said of compositions sung in
the old church', 'style, without instrumental accompaniment
; as, a mass a capella, i. e., a', 'mass purely vocal.']

This reads the whole file, assuming you want more than one item at a time. Note that you get a list of lines for each item - you may join them into a long string using
longline = ' '.join(lines)

--
Gabriel Genellina

Aug 18 '08 #1
0 856

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

Similar topics

18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
4
by: tgiles | last post by:
Hi, all. Another bewildered newbie struggling with Python goodness. This time it's searching strings. The goal is to search a string for a value. The string is a variable I assigned the name...
4
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the...
5
by: ingsms | last post by:
Hi, Does anyone have any suggestions on an approach to speed this up please? I need to check a given column in a given table to see whether there are any characters within any of the records...
3
by: Stewart Allen | last post by:
Hi there I'm trying to find part serial numbers between 2 numbers. The user selects a part number from a combo box and then enters a range of serial numbers into 2 text boxes and the resulting...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
8
by: Gordon Knote | last post by:
Hi can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++). The search should be as fast as possible and it would...
35
by: Cor | last post by:
Hallo, I have promised Jay B yesterday to do some tests. The subject was a string evaluation that Jon had send in. Jay B was in doubt what was better because there was a discussion in the C#...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.