Created
March 3, 2022 15:06
-
-
Save yayyar/7e90e7a0636686a53a9f6097e8388e41 to your computer and use it in GitHub Desktop.
Split data form String and turn to Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String url = | |
"https://www.rbdmyanmar.com/product/kiwi-colour-shine-protect-liquid/?attribute_pa_color=brown&attribute_pa_net-content=75ml&attribute_pa_pack-size=24-pcs"; | |
int urlIndex = url.indexOf('?'); | |
print('? index => $urlIndex'); | |
String newUrl = url.substring(urlIndex + 1, url.length); | |
print('newUrl => $newUrl'); | |
List attributeStr = newUrl.split("&"); | |
Map<String, String> variationMap = {}; | |
for (var item in attributeStr) { | |
String keyStr = item.split("=").first; | |
print('keyStr => $keyStr'); | |
int valueIndex = item.indexOf('='); | |
String valueStr = item.substring(valueIndex + 1, item.length); | |
print('valueStr => $valueStr'); | |
variationMap[keyStr] = valueStr; | |
} | |
print('variationMap => $variationMap'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment