A. shell中分割字符串之后怎么取得最后一个东西的值如果可以的话,怎么将分割后的结果保存到一个数组中
1、首先在shell中,定义一个字符串变量,例:str='bbc123uu789'。
由于Xcode对中文支持良好,所以在开发过程中经常直接使用中文字符串。
不过苹果推荐多语言化,需要为中文字符串添加个NSLocalizedString宏。
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''''
Localization The Objective-C Code
@"..." --> NSLocalizedString(@"...", nil)
Jason Lee 2012-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宏。
C. LINUX下我的split函数返回【ljava.lang.string这是怎么回事
split把字符串分割后,返回的类型是数组String[]类型。你得用数组接收
D. 这段linux命令什么意思“ls -al / | split -l 10 - lsroot”
1、列出/usr/lib目录下含有字符串“libevent”的文件和目录 2、ls即 list directory contents列出目录内容;其中的-a选项代表列出所有,包括隐藏文件;-l选项是列出文件的详细信息,每行只列出一个文件。如下面所示:root@localhost ~]#ls-a...
E. shell中有类似于awk中的split()函数来分割字符串的命令吗
用cut最简便(参见 小米肥猫 的回答)。
另外,Bash中特有的字符串处理方法(掐头去尾法)也比较常用(参见下面的链接)。
对于这道题来说:
var=“dfhjk_fewsk>dfakhi=vshbjy_df>brfdgr<rewrt"
tmp=${var#*>} #掐头,最小匹配(去除从前往后第一个>及前面的所有字符)
echo ${tmp%%>*} #去尾,最大匹配(去除从后往前最后一个>及后面的所有字符)
助记口诀:
# 表示掐头, 因为键盘上 # 在 $ 的左面。
% 表示去尾, 因为键盘上 % 在 $ 的右面。
单个#或%的表示最小匹配,双个#或%表示最大匹配(即,当有多种匹配方案的时候,选择匹配的最大长度还是最小长度)。
F. LINUX中用sed切分字符串的问题,急!
用cut不可以么
cut -c1-4 filename
再用一个while循环切出来
G. linux 如何截取制定分隔符中的字符串
[root@centos~]#echoF0101_ACC_ORT_RRR_20151209_4_2227647.txt|awk-F"_"'{print$1$5$6}'
F0101201512094
这样?
H. linux下分割字符串已经如何正则匹配日期与IP
你这个可用多个方法,最简单的可用grep
如
s="Connections: authenticated: 10.0.115.172::56498, as admin (Full access)"
echo $s | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+::[0-9]+"
结果
10.0.115.172::56498
这个正则相关的学习,对于学习Linux来说也是非常重要的,刘老师的新书《linux就该这么学》,关于这块讲解得非常透彻,你可以翻阅查看一下。
I. java中如何使.split()用回车来分割
public class exesice02
{
public static void main(String[] args)
{
System.out.println("床前明月光\t疑是地上霜\t举头望明月\t低头思故乡");
String shi = "床前明月光\t疑是地上霜\t举头望明月\t低头思故乡";
String[] poetry = shi.split("\t");
for(int i=0;i<poetry.length;i++)
{
System.out.println(poetry[i]);
}
}
}
J. Linux下如何用一个指定的字符串去分割另一个字符串
Linux下可以用strstr()函数定位子串所在的位置,用来实现用子串分隔一个字符串。man strstr可以看函数相关介绍
$manstrstr
NAME
strstr-locateasubstring
SYNOPSIS
#include<string.h>
char*strstr(constchar*haystack,constchar*needle);
DESCRIPTION
Thestrstr().Theterminating` 'charactersarenotcompared.
strstr()函数实现从haystack串中,查找第一次出现的needle子串,只比较有效字符,结束符 不算在内。
如:
#include<stdio.h>
#include<string.h>
intmain()
{
chars[]="abc@#123@#def@456@#ghi#789";
charsub[]="@#";
char*pc,*pb;
pb=pc=s;//pb指向字符串头
while(pc=strstr(pc,sub))//查找匹配字符串位置
{
*pc='