Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 2nd, 2008, 12:58 PM   #1
seVor
.NET Ninja - python newb
 
seVor's Avatar
 
Join Date: Apr 2008
Posts: 13
Rep Power: 0 seVor is on a distinguished road
Help with strings

Ok so I am trying to created a app that will loop through a folder and delete files with names that contains key words (ie: 'copy'). I have done some research and tried a few things but cant quite get it to work. Is there a way to check if 'copy' is in a string. Like a .contains() or something. Thanks for your help
__________________
The way programmers percive beauty is intimately related to their ability to process and understand complexity.
seVor is offline   Reply With Quote
Old May 2nd, 2008, 1:09 PM   #2
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Help with strings

indeed there is

Python Syntax (Toggle Plain Text)
  1. teststring = "hello there"
  2. z = teststring.find("there")
  3. print z

What will be printed out is there position of the first character of the substring "there".

Hope this help,

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old May 2nd, 2008, 3:18 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,786
Rep Power: 5 Sane will become famous soon enough
Re: Help with strings

It gets even simpler than that. You can use the "in" operator to test for the occurrence of a string within another string. For example, the following program will search for the string "quey" within every file inside all directories and subdirectories of "fdir".

Python Syntax (Toggle Plain Text)
  1. import os
  2.  
  3. query = "localhost".lower()
  4. fdir = 'aaron_storage'
  5.  
  6. for root, dirs, files in os.walk(fdir):
  7. for file in files:
  8. fname = os.path.join(root, file)
  9. if query in open(fname, 'r').read().lower():
  10. print '\n' + fname
  11. print '.',
  12.  
  13. raw_input('Done')
Sane is offline   Reply With Quote
Old May 5th, 2008, 2:16 PM   #4
seVor
.NET Ninja - python newb
 
seVor's Avatar
 
Join Date: Apr 2008
Posts: 13
Rep Power: 0 seVor is on a distinguished road
Re: Help with strings

SWEET.... You all are gods!! and I am a newb.... lol
__________________
The way programmers percive beauty is intimately related to their ability to process and understand complexity.
seVor is offline   Reply With Quote
Old May 5th, 2008, 2:17 PM   #5
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Help with strings

Gods, nah God yes (Sane) fool who likes to think he knows something about programming (me) lol.
Glad everything is working for you, if it is of course

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old May 5th, 2008, 2:21 PM   #6
seVor
.NET Ninja - python newb
 
seVor's Avatar
 
Join Date: Apr 2008
Posts: 13
Rep Power: 0 seVor is on a distinguished road
Re: Help with strings

Yeah.. I am a .net guru but falling head over heals for linux. PHP and python are awsome.
__________________
The way programmers percive beauty is intimately related to their ability to process and understand complexity.
seVor is offline   Reply With Quote
Old May 5th, 2008, 2:24 PM   #7
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Help with strings

Personally unfortunatley i know little of any language, i just know some Python, C++, Java, VB.NET, PHP, JavaScript. But i kinda enjoy knowing a little in each, i hope to be able to gain a better understanding in one area though.

As well as do alot of work on algorithms its just finding time inbetween college, hopefull i'll be able to build on things when i reach uni in a specialized language most likely Java.

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old May 5th, 2008, 2:26 PM   #8
seVor
.NET Ninja - python newb
 
seVor's Avatar
 
Join Date: Apr 2008
Posts: 13
Rep Power: 0 seVor is on a distinguished road
Re: Help with strings

well sounds like you have a good start. Just keep up the learning and it will be great. I recommend also learning MySQL
__________________
The way programmers percive beauty is intimately related to their ability to process and understand complexity.
seVor is offline   Reply With Quote
Old May 5th, 2008, 2:29 PM   #9
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Help with strings

Indeed i do need to look into SQL not just specifically for MySQL but for all database software, once again though it is finding time. I use to know the basics of it when i first began to look into PHP in detail but since then i have lost track of it due to the fact i don't use PHP all that often and what little i did got pussed aside for GCSE exams and then college

thanks for the tip though

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old May 5th, 2008, 2:39 PM   #10
seVor
.NET Ninja - python newb
 
seVor's Avatar
 
Join Date: Apr 2008
Posts: 13
Rep Power: 0 seVor is on a distinguished road
Re: Help with strings

yeah... I know MSSQL but its not a free solution. You can pretty much get the gist with MySQL. I am wanting to learn how to access a MySQL database via python. I have some ideas for cracking the md5 ecryption. I know that I will prob never crack it but hey, it might be fun to give it a shot.
__________________
The way programmers percive beauty is intimately related to their ability to process and understand complexity.
seVor is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The immutability of strings Arla C# 5 Apr 8th, 2008 1:58 PM
Splitting strings into other strings Keiro C 2 Dec 11th, 2006 6:10 AM
inserting strings into other strings codylee270 C 2 Dec 3rd, 2005 9:37 PM
Question about multidimensional arrays of strings aznluvsmc C 8 Oct 15th, 2005 10:20 PM
pointers strings, and strcat() conbrio C 3 Apr 16th, 2005 1:23 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC