I've searched many threads here on removing the first two lines of a string but I can't seem to get it to work with every solution I've tried.
Here is what my string looks like:
version 1.00 6992 [-4.32063, -9.1198, -106.59][0.00064, 0.99993, -0.01210][etc...]
I want to remove the first two lines of this Roblox mesh file for a script I am using. How can I do that?
Use the strip() Function to Remove a Newline Character From the String in Python. The strip() function is used to remove both trailing and leading newlines from the string that it is being operated on. It also removes the whitespaces on both sides of the string.
The . rsplit method is the correct tool when operating from the end (i.e. the right side of the string). Assuming the last line is newline terminated, 3 splits are necessary. We can tell the (r)split not to do more, so no join is needed to put the split pieces together.
Use the . strip() method to remove whitespace and characters from the beginning and the end of a string. Use the . lstrip() method to remove whitespace and characters only from the beginning of a string.
I don't know what your end character is, but what about something like
postString = inputString.split("\n",2)[2]
The end character might need to be escaped, but that is what I would start with.
x="""version 1.00 6992 [-4.32063, -9.1198, -106.59][0.00064, 0.99993, -0.01210][etc...] abc asdda""" print "\n".join(x.split("\n")[2:])
You can simply do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With