How to get value from Dictionary string string

Hello everybody.
I need to get a specif value from Dictionary string string

This is the dictionary

Dictionary<string, string>(11) { { “Set-Cookie”, “sap-usercontext=sap-client=999; path=/,MYSAPSSO2=AjQxMDMBABhSAFAAQQBfAEkAVABfAFMAUwBDACAAIAACAAYwADEAMAADABBRAFoAMwAgACAAIAAgACAABAAYMgAwADIAMgAwADkAMQAzADAAOQAxADMABQAEAAAACAYAAlgACQACRQD%2fAVYwggFSBgkqhkiG9w0BBwKgggFDMIIBPwIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYIBHjCCARoCAQEwcDBkMQswCQYDVRRGEwJERTEcMBoGA1UEChMTU0FQIFRydXN0IENvbW11bml0eTETMBEGA1UECxMKU0FQIFdlYiBBUzEUMBIGA1UECxMLSTAwMjAyNTg5MTMxDDAKBgNVBAMTA1FaMwIICiAZBTAYCQEwCQYFKw4AAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTIyMDkxMzA5MTMzNlowIwYJKoZIhvcNAQkEMRYEFN1E2EoYidNTnBG9hjsfbX0cCw0dMAkGByqGSM44BAMELjAsAhRRyfmnNKvoSeayeLZOHLMCxvgPVwIUMz4K2TUJGPXeRzmrBqtI8Ilh3kY%3d; path=/; domain=.test.net; secure,SAP_SESSIONID_AAA_010=vnbZbID09FFaI57TvgDOVFiTYGgzRBLsoycAUFaSFLE%3d; path=/; secure” }, { “content-type”, “application/xml” }, { “content-length”, “673” }, { “x-csrf-token”, “EPWDW8_9e_ghWZQAxxDa2F==” }, { “last-modified”, “Tue, 16 Aug 2022 09:45:32 GMT” }, { “cache-control”, “max-age=0” }, { “dataserviceversion”, “2.0” }, { “sap-processing-info”, “ODataBEP=,crp=,st=,MedCacheHub=Table,codeployed=,softstate=” }, { “sap-server”, “true” }, { “sap-perf-fesrec”, “43553.000000” }, { “content-encoding”, “” } }

I need to extract from Set-Cookie the value of MYSAPSSO2

The final variable is
str_cookie = AjQxMDMBABhSAFAAQQBfAEkAVABfAFMAUwBDACAAIAACAAYwADEAMAADABBRAFoAMwAgACAAIAAgAC…

What can i do ? i don’t understand how to do because it’s string and not object

Hi @l.sambinelli,
To get the value, you just use the key with the dictionary variable.
To get the “aaname”, you can just use the key that is being looped.

For each key In dict.Keys
    name = key.Get("aaname").ToString
    value = dict(key)

Hi,

How about the following sample?

System.Text.RegularExpressions.Regex.Match(cookie,"(?<=path=/,)\w+").Value

System.Text.RegularExpressions.Regex.Match(cookie,"(?<=path=/,\w+=)\w+").Value

Sample20220913-5.zip (3.0 KB)

Regards,

1 Like

Hi @l.sambinelli ,

Firstly, You could access the value of Set-Cookie :

setCookieValue = yourDict("Set-Cookie").ToString

Next, you could perform String /Regex Operations to get the value required :

Expression :

System.Text.RegularExpressions.Regex.Match(setCookieValue,"(?<=MYSAPSSO2=).*?(?=;)").Value.ToString
1 Like

OK , so the only solution is REgex. Thanks
now i try!

1 Like

thanks it’s perfect!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.