linux c语言字符串连接函数

linux c语言字符串连接函数,第1张

可以使用strcat()函数,函数原型char *strcat(char *dest,const char *src)函数说明:strcat()会将参数src字符串拷贝到参数dest所指的字符串尾。第一个参数dest要有足够的空间来容纳要拷贝的字符串。返回值:返回参数dest的字符串起始地址。

例子:

#include<string.h>

main()

{

char a[30]="string1"

char b[]="string2"

printf("before strcat():%s\n",a)

printf("after strcat():%s\n",strcat(a,b))

}

执行结果:

before strcat():string1

after strcat():string1string2

 由于Xcode对中文支持良好,所以在开发过程中经常直接使用中文字符串。

不过苹果推荐多语言化,需要为中文字符串添加个NSLocalizedString宏。

#!/usr/bin/python

# -*- coding: utf-8 -*-

'''''

Localization The Objective-C Code

@"..." --> NSLocalizedString(@"...", nil)

Jason Lee2012-03-01

'''

import os, sys

import re

import codecs

targetPattern = pile('@"[^"]+"')

global newFile, newFilePointer

def isChineseCharacter(ch):

return0x4e00 <= ord(ch) <= 0x9fa5

def hasChineseCharacter(str):

for char in str:

if isChineseCharacter(char):

returnTrue

returnFalse

def buildNewString(oldStr):

newStrPrefix = 'NSLocalizedString('

newStrSuffix = ', nil)'

newStr = newStrPrefix + oldStr + newStrSuffix

return newStr

def processLine(line):

global newFile, newFilePointer

matchResult = targetPattern.findall(line)

for result in matchResult:

if hasChineseCharacter(result):

#print result, buildNewString(result)

p = pile(result)

line = p.sub(buildNewString(result), line)

newFilePointer.write(line)

def processFile(filename):

#Xcode file is saved with utf-8

global newFile, newFilePointer

newFile = 'Replaced.' + filename

newFilePointer = codecs.open(newFile, 'wb', 'utf-8')

fp = codecs.open(filename, 'rb', 'utf-8')

for line in fp:

processLine(line)

fp.close()

newFilePointer.close()

oldFile = 'Old.' + filename

os.system('mv ' + filename + ' ' + oldFile)

os.system('mv ' + newFile + ' ' + filename)

#os.system('rm -f ' + oldFile)

if __name__ == "__main__":

if len(sys.argv) >1:

output = os.popen('ls ' + sys.argv[1]).read()

filelist = re.split('\n', output)

filelist = filelist[:-1]

#print filelist

print'Localizing...'

for file in filelist:

if os.path.exists(file):

try:

#print 'Processing File :', file

processFile(file)

except Exception as e:

print e

print'Localization Done.'

之后需要做的事情参考:

代码没用经过严格验证,请慎用。起码,没有检查该字符串是否已经加了NSLocalizedString宏。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/6103008.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-14
下一篇2023-03-14

发表评论

登录后才能评论

评论列表(0条)

    保存