473,406 Members | 2,345 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,406 software developers and data experts.

how to retrieve strings from within strings

6
Hi

I need to ask something

I am trying to retrieve a value from a string and I have noticed the following:

Scenario:
- I have retrieved lines from a file and need to read each line to retreive a certain string from the line i.e.
LINE = "THISISATEST"
I would need to retrieve the work TEST for processing.

I have noticed that when I declare string - and then parse for the value like string[8:4] it gives me a blank, but when I say string[8:len(string)], I get a value.

The problem comes in when I am trying to retrieve a value before the end of the string i.e. If I had to get the value ISA.

How do I do it, because using the string[0:0] format does not work - or does it?

Am I using it incorrectly?

Should I be using something like the find/ rfind command?

Thanks
Yudesh
Mar 5 '08 #1
3 1845
bgeddy
16
You're using slicing incorrectly. The format is string[X:Y:Z] where X=start position (starts from 0), Y=non inclusive end position and Z=step.

So :
string="THISISATESTISNTIT"
string[7:11]="TEST

Check out slicing in the docs..

You could use :

if "TEST" in string:

to just test for the existence of "TEST" in the string.
Mar 5 '08 #2
jlm699
314 100+
Expand|Select|Wrap|Line Numbers
  1. >>> srch = 'isa'
  2. >>> st = 'thisisateststring'
  3. >>> st[st.find(srch):st.find(srch)+len(srch)]
  4. 'isa'
  5. >>>
  6.  
Using a combination of find and the slicing will enable you to have a little more flexibility with your code
Mar 5 '08 #3
Yudesh
6
Thanks for the info guys - I will put it to good use
Mar 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
2
by: sparks | last post by:
ok I was trying to do something real simple I thought Me.Clinic.DefaultValue = Me.Clinic.Value I got error either ! or . misused or not found...something like that I thought ok how can you not...
4
by: Rémy Samulski | last post by:
Dear readers, How can I obtain all AD Objects within a OU? I can find all AD Objects in the root of my Active Directory when I use the DirectorySearcher and passing the DirectoryEntry I find...
9
by: Bilgehan.Balban | last post by:
Hi, For a declaration such as: char * mystring = "ABCDabcd123"; Is it a linker issue where such strings are stored in C, or is it defined as part of the language definition? Is there any...
0
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a...
9
by: Don | last post by:
Say I have a class like so: Public Class MyClass Public Prop1 as Integer Public Prop2 As Integer Public Prop3 As Integer End Class Is it possible to retrieve a list of the variables or...
7
by: Flavio | last post by:
Hi, I have a QListview widget that allows me to store a bunch of strings in it. This strings can be visualized, sorted, selected, etc. My Problem is that I cant find a way to get the user...
3
by: Nathan Guill | last post by:
I have an interface that works with an Access back-end. I would like to store and/or load user defined query strings per each user (i.e. no user can access another's queries). The idea I had was...
5
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, I've created a class library assembly containing several string resource files, like: - TableColumns.resx - TableColumns.de.resx - General.resx - General.de.resx
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...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.