Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 Ruby 获取字符串的一部分?我想image/jpeg从此字符串中获取值:
image/jpeg
"Content-Disposition: form-data; name='arquivo'; filename='the_last_in_line.jpg' Content-Type: image/jpeg"
你试过什么?您可以对此类任务使用正则表达式:
str='Content-Disposition: form-data; name="arquivo"; filename="the_last_in_line.jpg" Content-Type: image/jpeg' str[/Content-Type:\s*(\S*)/,1] # => "image/jpeg"