Removing a character from a string in Python using strip() -


i have 2 strings.

dat: "13/08/08 tim: 12:05:51+22" 

i want " character stripped both strings. here code using:

dat=dat.strip('"') tim=tim.strip('"') 

the resulting strings are:

dat: 13/08/08 tim: 12:05:51+22" 

why " character not removed tim?

according documentation here (http://www.tutorialspoint.com/python/string_strip.htm) should work.

according docs, strip([chars]):

return copy of string leading , trailing characters removed. chars argument string specifying set of characters removed.

so, " won't replaced dat: "13/08/08 , replaced tim: 12:05:51+22" because here " @ end:

>>> dat = 'dat: "13/08/08' >>> tim = 'tim: 12:05:51+22"' >>> dat.strip('"') 'dat: "13/08/08' >>> tim.strip('"') 'tim: 12:05:51+22' 

use replace() instead:

>>> dat.replace('"', '') 'dat: 13/08/08' >>> tim.replace('"', '') 'tim: 12:05:51+22' 

Comments

  1. Hello Admin,

    I'm wearing down a Java adventure that uses the JNI. The JNI considers a custom library that I've thought of myself, assume mylib.dll, and that depends upon a pariah library, libsndfile-1.dll.

    Exactly when I run my program it crashes with java.lang.UnsatisfiedLinkError: C:...path...\mylib.dll: Can't find subordinate libraries.

    Regards,
    Thanks

    RITU

    ReplyDelete

Post a Comment

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -