2013-02-24 162 views
-2

我如何使用Ruby獲取字符串的一部分?我想從這個字符串中獲得值image/jpeg如何從字符串中獲取值?

"Content-Disposition: form-data; name="arquivo"; filename="the_last_in_line.jpg" Content-Type: image/jpeg" 
+1

該字符串是非法的。您不能使用包含雙引號的雙引號字符串。 – 2013-02-24 18:26:15

回答

3

你試過了什麼?您可以使用正則表達式執行此類任務:

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"