- //判断输入文本中字符串的长度
- if ([self convertToInt:chooseRollTextField.text] > 20) {
- [self showToast:@"输入的角色名不能超过20个汉字或40个字符哦!"];
- return;
- }
- - (int)convertToInt:(NSString*)strtemp {
- int strlength = 0;
- char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
- for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
- if (*p) {
- p++;
- strlength++;
- }
- else {
- p++;
- }
- }
- int result = (strlength+1)/2;
- return result;
- }
来源: http://www.phpxs.com/code/1005614/