Search code examples
jython

jython ltrim a string after the first comma


How can I ltrim a string and return everything after the first comma. For example: Tools - Hand,Hand Tool - Porta Power, Cylinder, 50 T I want to return: Hand Tool - Porta Power, Cylinder, 50 T The number of letters vary before the first comma in the descriptions and there are multiple commas in the string.


Solution

  • To remove the part before the first comma (and the comma itself), use the str.partition method:

    s = "Tools - Hand,Hand Tool - Porta Power, Cylinder, 50 T"
    print s.partition(",")[2]  
    

    Output:

    Hand Tool - Porta Power, Cylinder, 50 T