473,382 Members | 1,545 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,382 software developers and data experts.

using the string functions (ex. find()) on a multi-symbol string

How can i use the find() function on a string that is composed of tons
of symbols that cause errors...

THis is my string:

find("<html><head><meta name="qrichtext" content="1" /><style
type="text/css">p, li { white-space: pre-wrap; }</style></head><body
style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:
400; font-style:normal; text-decoration:none;"><p style=" margin-top:
0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-
indent:0; text-indent:0px; font-size:8pt;"><span style=" font-size:
10pt; color:green;">Connected!</span></p></body></html>","margin")

The tough part about this is that the string is dynamically produced.
So I can't manually go into the string and eliminate the quote-marks
or to "literal-character" them.
Jun 27 '08 #1
2 1778
On Jun 18, 7:12 am, korean_dave <davidrey...@gmail.comwrote:
How can i use the find() function on a string that is composed of tons
of symbols that cause errors...

THis is my string:

find("<html><head><meta name="qrichtext" content="1" /><style
type="text/css">p, li { white-space: pre-wrap; }</style></head><body
style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:
400; font-style:normal; text-decoration:none;"><p style=" margin-top:
0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-
indent:0; text-indent:0px; font-size:8pt;"><span style=" font-size:
10pt; color:green;">Connected!</span></p></body></html>","margin")

The tough part about this is that the string is dynamically produced.
So I can't manually go into the string and eliminate the quote-marks
or to "literal-character" them.
What are you trying to find? What error(s) do you get?
Jun 27 '08 #2
On Jun 18, 7:12 am, korean_dave <davidrey...@gmail.comwrote:
How can i use the find() function on a string that is composed of tons
of symbols that cause errors...

THis is my string:

find("<html><head><meta name="qrichtext" content="1" /><style
type="text/css">p, li { white-space: pre-wrap; }</style></head><body
style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:
400; font-style:normal; text-decoration:none;"><p style=" margin-top:
0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-
indent:0; text-indent:0px; font-size:8pt;"><span style=" font-size:
10pt; color:green;">Connected!</span></p></body></html>","margin")

The tough part about this is that the string is dynamically produced.
So I can't manually go into the string and eliminate the quote-marks
or to "literal-character" them.
If as you say the string is dynamically created, your script should
have a variable name for it e.g. dynstr so all you have to do is:
dynstr.find("margin")
Note: you should be using str methods (see http://docs.python.org/lib/string-methods.html);
almost all functionality in the string module is now deprecated and
redirected (slowly) e.g.
def find(s, t):
return s.find(t)

If you really want/need to put such a monster string containing both '
and " as a literal in your script, you can use triple quotes (""" or
''').

I.e.
find("""<html><head><meta name="qrichtext" ... </span></p></body></
html>""", "margin")

See http://docs.python.org/tut/node5.htm...00000000000000

HTH,
John
Jun 27 '08 #3

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

Similar topics

8
by: Eric Linders | last post by:
Hi, I'm trying to figure out the most efficient method for taking the first character in a string (which will be a number), and use it as a variable to check to see if the other numbers in the...
2
by: John F Dutcher | last post by:
There must be a 'fundamental' reason why 'string' functions are reported as 'not found' even though the 'import string' statement is present. If the script has user-defined functions at its...
0
by: Igor2004 | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string...
1
by: George | last post by:
I am new to VB, I need 2 string functions to return last char and remove last char. I made them up. Am I recreating the wheel? do similar functions exist in String? I could not find them ...
4
by: Harro de Jong | last post by:
(absolute beginner here, sorry if this seems basic) Section 7.10 of 'How to Think Like a Computer Scientist' contains this discussion of string.find and other string functions: (quote) We can...
3
by: Hitesh | last post by:
Hi, In python doc -- 4.1.4 Deprecated string functions -- I read that "The following list of functions are also defined as methods of string and Unicode objects; see ``String Methods'' (section...
4
by: xdevel | last post by:
Hi, if I want to read the string functions source code (i.e. strcpy, strtok etc.) where can I find them?
3
by: Babikie | last post by:
Write a program that performs a reverse recursion with following functions. void swop (char,int,int); void reverse (char); void rev(char,int, int); User should enter a string and all character...
9
by: Ben Bacarisse | last post by:
I am porting a program from the Windows world to the Linux world. The source uses MS's new "safer" string functions such as: strcat_s(dest, size, source); but there are also calls such as: ...
15
by: Cartoper | last post by:
There is one little static C library to manage the serial number and unlock key for my application. Today it is compiled with Microsoft VC6 and linked into both VC6 modules and VS2005 modules. It...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.