2015-05-12 40 views
1

我有一個字符串,像這樣:ASP.NET將字符串拆分成不能從objective-c工作的數組?

~SEWER/FLATWORK SUPPLY & INSTALL - 25% of CONTRACT*~SEWER/FLATWORK SUPPLY & INSTALL - 75% of CONTRACT*SUMP PUMP PIT

,這是從這個未來:

string Items = Request.QueryString["Items"]; 

,然後我把這個字符串並通過*字符分割:

var ItemsArray = Items.Split('*'); 

但ItemsArray只返回:

~SEWER/FLATWORK SUPPLY 

下面是一些有趣的事情,串項返回:〜下水道/燙平供應量也:

這裏是長什麼樣的項目,如在URL:

Items=~SEWER/FLATWORK%20SUPPLY%20&%20INSTALL%20-%2025%25%20of%20CONTRACT*~SEWER/FLATWORK%20SUPPLY%20&%20INSTALL%20-%2075%25%20of%20CONTRACT*SUMP%20PUMP%20PIT 

我在objective-創建這個項目ç像這樣:

[Items appendString:[object objectForKey:@"Items"]]; 
[Items appendString:@"*"]; 
[Items deleteCharactersInRange:NSMakeRange([Items length]-1, 1)]; 
//This returns this: ~SEWER/FLATWORK SUPPLY & INSTALL - 25% of CONTRACT*~SEWER/FLATWORK SUPPLY & INSTALL - 75% of CONTRACT*SUMP PUMP PIT 

//add Items to URL 
NSString *fullURL = [NSString stringWithFormat:@"https://example.com?Items=%@, [Items stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

我期待的陣列返回,像這樣:

~SEWER/FLATWORK SUPPLY & INSTALL - 25% of CONTRACT 
~SEWER/FLATWORK SUPPLY & INSTALL - 75% of CONTRACT 
SUMP PUMP PIT 

這裏怎麼回事?

+0

問題是,'空間和space'是'%20%20',但應'%20%26%20'以防止解析爲查詢字符串參數 –

+0

我將如何執行@AlexK。 – user979331

+0

你會改變url編碼,使它在你的obj-c代碼中編碼'&',我不知道那種語言。 –

回答

1

首先你需要刪除HTTP編碼,然後你可以拆分你的字符串。嘗試以下方法。 您需要添加兩個命名空間:System.Web程序& System.Text.RegularExpressions

string Items = Request.QueryString["Items"]; 
Items = HttpUtility.UrlDecode(Items); 
string[] ItemsArray = Regex.Split(Items, "*"); 

希望這有助於你...