开发者

Split/Reformat String

开发者 https://www.devze.com 2023-03-27 17:17 出处:网络
I want to split a string and replac开发者_运维百科e some values. The string is a date that looks like this \'08/26/2009\' I want to reformat it so that it replaces the / with a - so that it looks like

I want to split a string and replac开发者_运维百科e some values. The string is a date that looks like this '08/26/2009' I want to reformat it so that it replaces the / with a - so that it looks like this '08-26-2009'

The string is passed into a variable y, so my line looks like this

test = y.split("/")
print y

return this ['8', '26', '2009']

I just can't figure out how to reformat it to place the dash between the day month and year.

Thanks Mike


You can use replace instead of split.

test = y.replace('/', '-');

(assuming this is Java)

0

精彩评论

暂无评论...
验证码 换一张
取 消