/// split a string into multiple sub strings, based on a separator string
/// for example, if separator="::",
///
/// s = "abc" -> "abc"
///
/// s = "abc::def xy::st:" -> "abc", "def xy" and "st:",
///
/// s = "::abc::" -> "abc"
///
/// s = "::" -> NO sub strings found
///
/// s = "" -> NO sub strings found
///
/// then append the sub-strings to the end of the vector v.
///
/// the idea comes from the findUrls() function of "Accelerated C++", chapt7,
/// findurls.cpp
///
void split(const string& s, const string& sep, vector<string>& v)
{
typedef string::const_iterator iter;
iter b = s.begin(), e = s.end(), i;
iter sep_b = sep.begin(), sep_e = sep.end();
// search through s
while (b != e){
i = search(b, e, sep_b, sep_e);
// no more separator found
if (i == e){
// it's not an empty string
if (b != e)
v.push_back(string(b, e));
break;
}
else if (i == b){
// the separator is found and right at the beginning
// in this case, we need to move on and search for the
// next separator
b = i + sep.length();
}
else{
// found the separator
v.push_back(string(b, i));
b = i;
}
}
}
Библиотека ускорения хороша, но они не всегда доступны. Выполнение такого рода вещей вручную также является хорошим упражнением на мозг. Здесь мы просто используем алгоритм std :: search () из STL, см. Приведенный выше код.
Если вы хотите использовать методы SOAP на своем сайте ASP.NET, используйте Sudzc (http://sudzc.com/).
Он сгенерирует пакет со всем исходным кодом и классами Objective-C, написанными для вас, для взаимодействия с вашими веб-службами SOAP. Вы можете добавить его в свой проект для iPhone, и все готово.
Вы можете настроить сгенерированный код. Огромная экономия времени :)