user8817894
user8817894

Reputation:

display only a certain word in a string

I'm making an API call that fetches me something like

Session #1 - ABC
Session #2 - DEF
Session #3 - PQR

I want to render only the values after the hyphen (ABC, DEF, PQR) on a page.

Logically, remove all the characters upto the nth character(hyphen, in this case). How do I do that, though?

Upvotes: 0

Views: 152

Answers (1)

Joe
Joe

Reputation: 12417

You can use split and take the second argument:

split('-')[1].strip()

Example:

f = "Session #1 - ABC"
s = f.split('-')[1].strip()

Output:

ABC

Upvotes: 2

Related Questions