-2

Hello i have a string that looks like that

el-gu-en-tr-ca-it-eu-ca@valencia-ar-eo-cs-et-th_TH-gl-id-es-bn_IN-ru-he-nl-pt-no-nb-id_ID-lv-lt-pa-te-pl-ta-bg_BG-be-fr-de-bn_BD-uk-pt_BR-ast-hr-jv-zh_TW-sr@latin-da-fa-hi-tr_TR-fi-hu-ja-fo-bs_BA-ro-fa_IR-zh_CN-sr-sq-mn-ko-sv-km-sk-km_KH-en_GB-ms-sc-ug-bal 

how can i break items by - and place them in an array like

array[0]->el
array[1]->gu
.....
4

2 に答える 2

6

.split()文字列で次のメソッドを使用します。

>>> example = 'el-gu-en-tr-ca-it-eu-ca@valencia-ar-eo-cs-et-th_TH-gl-id-es-bn_IN-ru-he-nl-pt-no-nb-id_ID-lv-lt-pa-te-pl-ta-bg_BG-be-fr-de-bn_BD-uk-pt_BR-ast-hr-jv-zh_TW-sr@latin-da-fa-hi-tr_TR-fi-hu-ja-fo-bs_BA-ro-fa_IR-zh_CN-sr-sq-mn-ko-sv-km-sk-km_KH-en_GB-ms-sc-ug-bal'
>>> example.split('-')
['el', 'gu', 'en', 'tr', 'ca', 'it', 'eu', 'ca@valencia', 'ar', 'eo', 'cs', 'et', 'th_TH', 'gl', 'id', 'es', 'bn_IN', 'ru', 'he', 'nl', 'pt', 'no', 'nb', 'id_ID', 'lv', 'lt', 'pa', 'te', 'pl', 'ta', 'bg_BG', 'be', 'fr', 'de', 'bn_BD', 'uk', 'pt_BR', 'ast', 'hr', 'jv', 'zh_TW', 'sr@latin', 'da', 'fa', 'hi', 'tr_TR', 'fi', 'hu', 'ja', 'fo', 'bs_BA', 'ro', 'fa_IR', 'zh_CN', 'sr', 'sq', 'mn', 'ko', 'sv', 'km', 'sk', 'km_KH', 'en_GB', 'ms', 'sc', 'ug', 'bal']
于 2012-07-31T13:05:33.163 に答える
3

電話str.split()

s = "el-gu-en-tr-ca-it-eu-ca@valencia-ar-eo-cs-et-th_TH-gl-id-es-bn_IN-ru-he-nl-pt-no-nb-id_ID-lv-lt-pa-te-pl-ta-bg_BG-be-fr-de-bn_BD-uk-pt_BR-ast-hr-jv-zh_TW-sr@latin-da-fa-hi-tr_TR-fi-hu-ja-fo-bs_BA-ro-fa_IR-zh_CN-sr-sq-mn-ko-sv-km-sk-km_KH-en_GB-ms-sc-ug-bal"
locales = s.split("-")
于 2012-07-31T13:05:53.903 に答える