0

I need to get value of Header "Set-Cookie" - sessid = EZEaqDixCNZKjY4HwEXSjuR8lKhqkHXGLX6SoZSmtdUegKP7AkUuFOpUIHygf3M5

Now I can get all string, but I need only value for sessid - EZEaqDixCNZKjY4HwEXSjuR8lKhqkHXGLX6SoZSmtdUegKP7AkUuFOpUIHygf3M5

How can I pars this String or give me advise how to get this property.

Case

1 Answers1

1
"sessid=EZEaqDixCNZKjY4HwEXSjuR8lKhqkHXGLX6SoZSmtdUegKP7AkUuFOpUIHygf3M5;".replacingOccurrences(of: "sessid=", with: "").dropLast()
// Result: EZEaqDixCNZKjY4HwEXSjuR8lKhqkHXGLX6SoZSmtdUegKP7AkUuFOpUIHygf3M5

First we remove "sessid=" and then dropping the semicolon.

fewlinesofcode
  • 3,007
  • 1
  • 13
  • 30
  • all string look like this `sessid=ETLqmdsPiBEfjw008XxEZNUvLpNif6sNC7ABF3jmepfduzhRPljzszx20af8PJtn; path=/, CurrentCulture=ru; path=/` – Vladimir Pchelyakov Oct 11 '18 at 10:37
  • `"sessid=ETLqmdsPiBEfjw008XxEZNUvLpNif6sNC7ABF3jmepfduzhRPljzszx20af8PJtn; path=/, CurrentCulture=ru; path=/".split(separator: ";").first?.replacingOccurrences(of: "sessid=", with: "")` One more step added - splitting string by semicolon and no more need in dropping last character – fewlinesofcode Oct 11 '18 at 10:41
  • It's solve my problem, but maybe there is a method to pars Headers in response? Thank you any way – Vladimir Pchelyakov Oct 11 '18 at 11:23
  • If you're asking about header parsing methods from `Foundation` framework, then i believe there is no. It's users responsibility to parse header values. – fewlinesofcode Oct 11 '18 at 12:19