| 1. |
Solve : Replacing spaces with underscores in a string? |
|
Answer» I have a string which has spaces in it, and I NEED to replace all of the spaces with UNDERSCORES: I have a string which has spaces in it, and I need to replace all of the spaces with underscores: if you have PYTHON Code: [Select]C:\>python -c "PRINT 'This is a string'.replace(' ','_') " This_is_a_string I do like the python solution, but once I get the return from the line: C:\>python -c "print 'This is a string'.replace(' ','_') " This_is_a_string (i.e. the part that says "This_is_a_string"), how do I put that part into a new string? Thanks, darrylwell since you have Python, just do a Python script Code: [Select]s = "This is my string" result = s.replace(" ", "_") #store the result in variable print result save the code as test.py. Then from command prompt, type c:\> python test.py |
|