我想从Swift的字符串的开头和结尾修剪public class EmployeeViewModel
{
public IEnumerable<SelectListItem> ListOfCompanies { get; set; }
public string SELECTED_COMPANY { get; set; }
//other props
}
。是否有任何建造或为此或什么是一个好方法来做到这一点?
答案 0 :(得分:2)
我喜欢在这种情况下使用var fullMessage = "This\n is\n my example\n message.\n Thanks Leigh Smith\n and some more characters\n and lots more \n"
var startName = fullMessage.rangeOfString("Leigh")
var endMessage = fullMessage[advance(startName!.endIndex,0)...advance(fullMessage.endIndex,-1)]
var posRange = endMessage.rangeOfString("\n")
var pos = posRange?.startIndex
var xpos = advance(startName!.endIndex, 0)
fullMessage = fullMessage[advance(fullMessage.startIndex, 0)...advance(startName!.endIndex,advance(pos, 0))]
,使用自定义字符集(此处只是&#34; /&#34;):
stringByTrimmingCharactersInSet
结果:&#34;字&#34;