
-----------------------------------
Sniper4Life
Wed Apr 15, 2009 6:35 pm

Strings
-----------------------------------
Could someone give me tutorial on the following subjects in pythong:     ????

- Slices
- Escape sequences
- len()
- String Methods
?	upper
?	lower
?	find
?	replace
?	count

Then I would like to know ALL ways you can manipulate a user's input.

ok also...when you have a string like "My foot" they are 2 seperate strings under one function or w/e...and is there any way
to program in python...so that the computer can identify WHERE the space is...when print the words out seperately? so what im basically asking for this question is how do you slice a user's input? like make the output come out SLICED

-----------------------------------
Alexmula
Wed Apr 15, 2009 8:44 pm

RE:Strings
-----------------------------------
look up the string module. and you can split "my foot" with the split function :lol:

-----------------------------------
Sniper4Life
Wed Apr 15, 2009 9:15 pm

RE:Strings
-----------------------------------
yes i know that but what im trying to say is can you do that WITH user input?
like split w/e they type?

-----------------------------------
wtd
Wed Apr 15, 2009 9:58 pm

RE:Strings
-----------------------------------
Can you get what users type into a string?

-----------------------------------
Sniper4Life
Thu Apr 16, 2009 7:19 am

RE:Strings
-----------------------------------
yes they need to write their fulll name so (First name) (Last name)

but every time...the number of characters can be different but it is only 2 words under one raw input every time

but i dont know how to slice that string
cus its user input

-----------------------------------
wtd
Thu Apr 16, 2009 12:45 pm

RE:Strings
-----------------------------------
A string is a string is a string.

-----------------------------------
Sniper4Life
Thu Apr 16, 2009 3:00 pm

RE:Strings
-----------------------------------
sigh just nvr mind...i dont even understand what i want answered :(
cus i understand all of the things i listed

but i just dont understand...how to manipulate...the user input...

-----------------------------------
Tony
Thu Apr 16, 2009 3:07 pm

RE:Strings
-----------------------------------
re-read this entire thread from the start. Your answer is in here already.

-----------------------------------
Dusk Eagle
Thu Apr 16, 2009 3:23 pm

Re: Strings
-----------------------------------
You're not manipulating anything while the user is entering input. But, once the user has entered input, is there any difference between a string generated like this:

string = raw_input()

and a string generated like this: 

string = "John Doe"


-----------------------------------
Sniper4Life
Thu Apr 16, 2009 4:41 pm

Re: Strings
-----------------------------------
ok this is basically what its like

[code]
string = raw_input ("Please enter your full name")
[/code]
the user can now enter ANY name
now
[code]
what would i enter here...so that W/E they inserted...can be split?
[/code]

and yes dusk there is
because raw input could be any name
it isnt nessessarily going to be John Doe
so...how can you make it so that you can split a string...without knowing what the string will be? but it has 2 words and 1 space in between it...???

-----------------------------------
Dusk Eagle
Thu Apr 16, 2009 6:02 pm

Re: Strings
-----------------------------------

namelength = 2 #Number of names we want (In this case, 2, as we just want a first and last name)
num_words = namelength + 1
while num_words > namelength:
	string = raw_input("Enter your name: ")
	string = string.split()
	num_words = len(string)
print "out of loop"


Is this what you're looking for?

-----------------------------------
Alexmula
Thu Apr 16, 2009 6:55 pm

RE:Strings
-----------------------------------
i believe this is what he means

name = raw_input("Enter name")
name = str(name)
splitName = name.split()
print splitName


-----------------------------------
Dusk Eagle
Thu Apr 16, 2009 7:07 pm

Re: RE:Strings
-----------------------------------
i believe this is what he means

name = raw_input("Enter name")
name = str(name)
splitName = name.split()
print splitName


That's basically what I did, except my code checks to make sure the user has only entered two words, and no more. (It doesn't check if the user entered less than two words, but that's easily fixable.) I have a question about your code though. What is name = str(name) supposed to do? I believe raw_input() automatically treats input as a string.

-----------------------------------
Alexmula
Thu Apr 16, 2009 7:13 pm

Re: RE:Strings
-----------------------------------
i believe this is what he means

name = raw_input("Enter name")
name = str(name)
splitName = name.split()
print splitName


That's basically what I did, except my code checks to make sure the user has only entered two words, and no more. (It doesn't check if the user entered less than two words, but that's easily fixable.) I have a question about your code though. What is name = str(name) supposed to do? I believe raw_input() automatically treats input as a string.
if you dont put that then some u's appear beside the names  :oops:  i dont even know what those u's represent :lol: :oops: anyone care to explain?

-----------------------------------
Dusk Eagle
Thu Apr 16, 2009 7:52 pm

Re: Strings
-----------------------------------
That's funny, I don't get that. Are you using CPython?

-----------------------------------
Alexmula
Thu Apr 16, 2009 8:38 pm

RE:Strings
-----------------------------------
i use PyScripter. python version 2.6.

-----------------------------------
Sniper4Life
Thu Apr 16, 2009 9:59 pm

Re: RE:Strings
-----------------------------------
i believe this is what he means

name = raw_input("Enter name")
name = str(name)
splitName = name.split()
print splitName




that....is exactly what i mean
but when you split it...will it split it into 2 names?
???

-----------------------------------
Dusk Eagle
Thu Apr 16, 2009 10:01 pm

Re: Strings
-----------------------------------
It will split into the number of spaces that are present in the string. You will have to do a bit of checking to ensure that there are exactly two words. You'll probably want to look into the len() function.

-----------------------------------
Sniper4Life
Thu Apr 16, 2009 10:05 pm

RE:Strings
-----------------------------------
wow....i am so stupid...i tried thinking so hard i forgot how to do things the simple way...sigh...thanks 
i can take it from here :D
i just wanted to know how to split 2 words
thats it

(2 words with user's input )
btw thanks guys for helping out with this 
i couldnt find the answer anywhere in google...and ive been stuck on it for a wile 
i was thinking but i forgot to just toy around with random methods...thanks
