如何拆分java中的unicode字符

时间:2017-05-24 22:48:34

标签: java unicode

我在java中有一个看起来像这样的字符串 -

“id\uFF1Aabc123, ip\uFF1A127:0:0:1”

如何基于\ uFF1A在java中拆分?到目前为止,我已尝试过这个 -

Pattern p = Pattern.compile("\uFF1A", Pattern.UNICODE_CHARACTER_CLASS);
System.out.println(p.split(s)[0]);

它只返回整个字符串。

1 个答案:

答案 0 :(得分:3)

您的代码有效。

但是,您可以使用String s = "id\uFF1Aabc123, ip\uFF1A127:0:0:1"; String[] splitted = s.split("\uFF1A"); System.out.println(splitted[0]); System.out.println(splitted[1]); System.out.println(splitted[2]); 方法:

Sub transfer()
Dim i As Long
Dim j As Long
Dim lastrow1 As Long
Dim lastrow2 As Long
Dim jobnum As String
Dim mainmachine As String
Dim WBT As Workbook ''''This Workbook
Dim WBC As Workbook ''''CapacitySummary workbook 

Set WBT = Workbooks("CNC TEST.xlsx")
Set WBC = Workbooks("CapacitySummary.xlsx")
lastrow1 = WBT.Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
lastrow2 = WBC.Worksheets("DATA").Range("A" & Rows.Count).End(xlUp).Row

WBT.Worksheets("sheet1").Activate
For i = 2 To lastrow1
jobnum = WBT.Sheets("Sheet1").Cells(i, "A").Value
mainmachine = WBT.Sheets("Sheet1").Cells(i, "K").Value
WBC.Worksheets("DATA").Activate


For j = 2 To lastrow2

If WBC.Worksheets("DATA").Cells(j, "A").Value = jobnum And WBC.Worksheets("DATA").Cells(j, "B").Value = mainmachine Then  ''  CapacitySummary workbook
WBC.Worksheets("DATA").Activate
WBC.Worksheets("DATA").Range(Cells(i, "N"), Cells(i, "N")).Copy

''''Choosing Range to copy
WBT.Worksheets("Sheet1").Activate
WBT.Worksheets("Sheet1").Range(Cells(j, "P"), Cells(j, "P")).Select
'Range.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
''''Choosing Range to paste

End If

Next j
Application.CutCopyMode = False

Next i



'Application.ScreenUpdating = True
'Stoptime = Time
'elapsedTime = (Stoptime - StartTime) * 24 * 60
'MsgBox "List Complete " & elapsedTime & " minutes. " & Chr(13)
'findConn.Close

End SubBC As Workbook ''''CapacitySummary workbook 

Set WBT = Workbooks("CNC TEST.xlsx")
Set WBC = Workbooks("CapacitySummary.xlsx")

lastrow1 = WBT.Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
lastrow2 = WBC.Worksheets("DATA").Range("A" & Rows.Count).End(xlUp).Row

WBT.Worksheets("sheet1").Activate
For i = 2 To lastrow1
jobnum = WBT.Sheets("Sheet1").Cells(i, "A").Value
mainmachine = WBT.Sheets("Sheet1").Cells(i, "K").Value
WBC.Worksheets("DATA").Activate


For j = 2 To lastrow2

If WBC.Worksheets("DATA").Cells(j, "A").Value = jobnum And WBC.Worksheets("DATA").Cells(j, "B").Value = mainmachine Then  ''  CapacitySummary workbook
WBC.Worksheets("DATA").Activate
WBC.Worksheets("DATA").Range(Cells(i, "N"), Cells(i, "N")).Copy

''''Choosing Range to copy
WBT.Worksheets("Sheet1").Activate
WBT.Worksheets("Sheet1").Range(Cells(j, "P"), Cells(j, "P")).Select
'Range.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
''''Choosing Range to paste

End If

Next j
Application.CutCopyMode = False

Next i



'Application.ScreenUpdating = True
'Stoptime = Time
'elapsedTime = (Stoptime - StartTime) * 24 * 60
'MsgBox "List Complete " & elapsedTime & " minutes. " & Chr(13)
'findConn.Close

DEMO