Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   string contains and special characters (http://www.velocityreviews.com/forums/t953194-string-contains-and-special-characters.html)

loial 10-09-2012 02:02 PM

string contains and special characters
 
I am trying to match a string that containing the "<" and ">" characters, using the string contains function, but it never seems to find the lines containing the string

e.g if mystring.contains("<TAG>") :

Do I need to escape the characters...and if so how?


Agon Hajdari 10-09-2012 02:10 PM

Re: string contains and special characters
 
On 10/09/2012 04:02 PM, loial wrote:
> I am trying to match a string that containing the "<" and ">" characters, using the string contains function, but it never seems to find the lines containing the string
>
> e.g if mystring.contains("<TAG>") :
>
> Do I need to escape the characters...and if so how?
>

if '<TAG>' in yourstring:
# your code

--
Agon Hajdari

Dave Angel 10-09-2012 02:23 PM

Re: string contains and special characters
 
On 10/09/2012 10:02 AM, loial wrote:
> I am trying to match a string that containing the "<" and ">" characters, using the string contains function, but it never seems to find the lines containing the string
>
> e.g if mystring.contains("<TAG>") :
>
> Do I need to escape the characters...and if so how?
>


What language are you trying to use, and what version of that language?
In all the Python versions I know of, that line would simply be a syntax
error. There's no "contains" method in the str class, use the 'in' keyword.

if "<TAG>' in mystring:

No need to escape any ASCII characters except backslash.

--

DaveA


Jerry Hill 10-09-2012 02:34 PM

Re: string contains and special characters
 
On Tue, Oct 9, 2012 at 10:02 AM, loial <jldunn2000@gmail.com> wrote:
> I am trying to match a string that containing the "<" and ">" characters, using the string contains function, but it never seems to find the lines containing the string
>
> e.g if mystring.contains("<TAG>") :
>
> Do I need to escape the characters...and if so how?


Strings don't have a contains() method. Assuming that mystring is
actually a string, you should be getting a very specific error,
telling you exactly what's wrong with your code (something like
AttributeError: 'str' object has no attribute 'contains').

If that isn't what you're seeing, you'll need to provide the full and
complete text of the error you are getting, and preferably enough of
your code that we can reproduce the issue and help you solve it.

--
Jerry

Mark Lawrence 10-09-2012 02:50 PM

Re: string contains and special characters
 
On 09/10/2012 15:23, Dave Angel wrote:
> On 10/09/2012 10:02 AM, loial wrote:
>> I am trying to match a string that containing the "<" and ">" characters, using the string contains function, but it never seems to find the lines containing the string
>>
>> e.g if mystring.contains("<TAG>") :
>>
>> Do I need to escape the characters...and if so how?
>>

>
> What language are you trying to use, and what version of that language?
> In all the Python versions I know of, that line would simply be a syntax
> error. There's no "contains" method in the str class, use the 'in' keyword.


I see you've already corrected youself :)

>
> if "<TAG>' in mystring:
>
> No need to escape any ASCII characters except backslash.
>


No need to escape anything if raw strings are used.

--
Cheers.

Mark Lawrence.


Ulrich Eckhardt 10-09-2012 02:59 PM

Re: string contains and special characters
 
Am 09.10.2012 16:02, schrieb loial:
> I am trying to match a string that containing the "<" and ">"
> characters, using the string contains function, but it never seems to
> find the lines containing the string
>
> e.g if mystring.contains("<TAG>") :


I can't locate a 'contains' function anywhere, what type is 'mystring'?


> Do I need to escape the characters...and if so how?


Maybe. Please provide some example code that unexpectedly fails.


Uli

loial 10-09-2012 03:09 PM

Re: string contains and special characters
 
On Tuesday, 9 October 2012 15:19:33 UTC+1, Agon Hajdari wrote:
> On 10/09/2012 04:02 PM, loial wrote: > I am trying to match a string thatcontaining the "<" and ">" characters, using the string contains function,but it never seems to find the lines containing the string > > e.g if mystring.contains("<TAG>") : > > Do I need to escape the characters...and if sohow? > if '<TAG>' in yourstring: # your code -- Agon Hajdari


That worked...thanks

loial 10-09-2012 03:09 PM

Re: string contains and special characters
 
On Tuesday, 9 October 2012 15:19:33 UTC+1, Agon Hajdari wrote:
> On 10/09/2012 04:02 PM, loial wrote: > I am trying to match a string thatcontaining the "<" and ">" characters, using the string contains function,but it never seems to find the lines containing the string > > e.g if mystring.contains("<TAG>") : > > Do I need to escape the characters...and if sohow? > if '<TAG>' in yourstring: # your code -- Agon Hajdari


That worked...thanks


All times are GMT. The time now is 03:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.