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='