Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > find() a larger string within a smaller string

Reply
Thread Tools

find() a larger string within a smaller string

 
 
korean_dave
Guest
Posts: n/a
 
      11-14-2008
stringa = "hi"
stringb = "hiyoooo"

I'd like it to return -1 when I do:

returnVal = stringa.find(stringb);

Instead, it treats stringa as "hi" and stringb as "hi".

How do I solve this?
 
Reply With Quote
 
 
 
 
Mensanator
Guest
Posts: n/a
 
      11-14-2008
On Nov 14, 1:20*pm, korean_dave <(E-Mail Removed)> wrote:
> stringa = "hi"
> stringb = "hiyoooo"
>
> I'd like it to return -1 when I do:
>
> returnVal = stringa.find(stringb);
>
> Instead, it treats stringa as "hi" and stringb as "hi".
>
> How do I solve this?


Try this:

>>> stringa = 'hi'
>>> stringb = 'hiyoo'
>>> stringa.find(stringb)

-1
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      11-14-2008
On Nov 15, 6:20*am, korean_dave <(E-Mail Removed)> wrote:
> stringa = "hi"
> stringb = "hiyoooo"
>
> I'd like it to return -1 when I do:
>
> returnVal = stringa.find(stringb);
>
> Instead, it treats stringa as "hi" and stringb as "hi".


You appear to be gravely mistaken:

| >>> stringa = "hi"
| >>> stringb = "hiyoooo"
| >>> returnVal = stringa.find(stringb);
| >>> returnVal
| -1

> How do I solve this?


You need to tell us why you thought so; then, maybe, we can help.

 
Reply With Quote
 
Gary Herron
Guest
Posts: n/a
 
      11-14-2008
korean_dave wrote:
> stringa = "hi"
> stringb = "hiyoooo"
>
> I'd like it to return -1 when I do:
>
> returnVal = stringa.find(stringb);
>
> Instead, it treats stringa as "hi" and stringb as "hi".
>


No it doesn't. stringb is "hiyoooo" and it "treats" it that way.
(And just what do you mean by "treat"?)

> How do I solve this?
>


There is nothing to solve. The expression

stringa.find(stringb)

asks if "hi" contains "hiyoooo", and since it does not, it returns a -1 indicating so.

You'll have to describe what you expected and why you expected it before we will be able to see a problem that needs solving. (And then the problem will most likely be in your expectations, not in the find method.)


Gary Herron



> --
> http://mail.python.org/mailman/listinfo/python-list
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
font of the active title bar appears smaller and smaller automatic =?Utf-8?B?dGhhbmt5b3U=?= Windows 64bit 1 10-12-2005 09:24 AM
dynamic range of digital, larger or smaller? Eolake Stobblehouse Digital Photography 102 07-03-2005 08:33 PM
DSLR, Smaller Sensor, Smaller TTL Viewfinder? Which has the largest? Geshu Iam Digital Photography 7 08-17-2004 06:52 PM
Re: Type casting- a larger type to a smaller type pete C Programming 4 04-02-2004 05:19 PM
Re: Type casting- a larger type to a smaller type heyo C Programming 3 04-01-2004 06:35 PM



Advertisments