早教吧作业答案频道 -->其他-->
Ultraedit数字求和有上万行两列数据,制表符分开,第1列为英语字母组合,第2列为冒号分开的2,3,4或5组数字(如下),需要计算出第2列中所有数字的合.以第一行“abc111:222:333”为例,需要得出“abc66
题目详情
Ultraedit 数字 求和
有上万行两列数据,制表符分开,第1列为英语字母组合,第2列为冒号分开的2,3,4或5组数字(如下),需要计算出第2列中所有数字的合.以第一行“abc 111:222:333”为例,需要得出“abc 666”这种结果,每行如此.如果不能用ultraedit实现,有没有更好的办法,因为行数太多,有可能超出10万行.
.
abc 111:222:333
aa 22875:185
aaaaa 1935:740:4435
a 783:494:480:121
aaaaaaa 277:25:238
bb 254:580:121
bbbbb 243:23:211
b 480:125:185
bbbbbbb 131:1027:740:121
cc 3598:264
ccccc 203:55
c 71:217
ccccccc 2054:2308
ccc 274:1776::121
aaa 868:1261:185
bbb 4435:50:00
.
有上万行两列数据,制表符分开,第1列为英语字母组合,第2列为冒号分开的2,3,4或5组数字(如下),需要计算出第2列中所有数字的合.以第一行“abc 111:222:333”为例,需要得出“abc 666”这种结果,每行如此.如果不能用ultraedit实现,有没有更好的办法,因为行数太多,有可能超出10万行.
.
abc 111:222:333
aa 22875:185
aaaaa 1935:740:4435
a 783:494:480:121
aaaaaaa 277:25:238
bb 254:580:121
bbbbb 243:23:211
b 480:125:185
bbbbbbb 131:1027:740:121
cc 3598:264
ccccc 203:55
c 71:217
ccccccc 2054:2308
ccc 274:1776::121
aaa 868:1261:185
bbb 4435:50:00
.
▼优质解答
答案和解析
Ultraedit 有运算功能,但主要是整列求和 菜单“列”下的“列/选区求和”
直接用 正则表达式 似乎不行.有两种途径:
1.把":"替换成制表符,然后整体拷贝到Excel中,在某列(如第6列)中写公式=b1+c1+d1+e1+f1,下拉适用所有,得出一样的结果.
2.用ultraedit的script也可以实现.
if (UltraEdit.document.length > 0) { // Is any file opened?
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.ueReOn();
/* Verify the line termination of the last line of the file
and insert one if the last line has no line termination.*/
UltraEdit.activeDocument.bottom();
if (UltraEdit.activeDocument.isColNumGt(1)) {
UltraEdit.activeDocument.insertLine();
if (UltraEdit.activeDocument.isColNumGt(1)) {
UltraEdit.activeDocument.deleteToStartOfLine();
}
}
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.trimTrailingSpaces();
// Define line terminator type by default for DOS.If the version of
// UE/UES has support for the line terminator property,use it to set
// the line terminator string according to the value of this property.
var sLineTerm = "\r\n";
if (typeof(UltraEdit.activeDocument.lineTerminator) == "number") {
if (UltraEdit.activeDocument.lineTerminator == 1) {
sLineTerm = "\n"; // UNIX file not converted to DOS.
} // Ignore older versions of UltraEdit and MAC files for this
} // script and use in all other cases also DOS line terminators.
UltraEdit.selectClipboard(9);
// Process entire file in blocks of 10000 lines to end of file.
var nLineNum = 1;
do {
nLineNum += 10000;
UltraEdit.activeDocument.gotoLineSelect(nLineNum,1);
if (!UltraEdit.activeDocument.isSel()) break;
var asLines = UltraEdit.activeDocument.selection.split(sLineTerm);
// Process each line of the selected block.
for (var nIndex = 0; nIndex < asLines.length; nIndex++ ) {
// Find first character of a sequence of colon delimited numbers at end of the line.
var nNumberPos = asLines[nIndex].search(/(?:\d+:*)+$/);
// If no number found,for example a blank line,skip the line.
if (nNumberPos < 0) continue;
// Split the line into fixed text and the numbers as string.
var sText = asLines[nIndex].substr(0,nNumberPos);
var sNumbers = asLines[nIndex].substr(nNumberPos);
// Split the numbers string up into an array of strings each with a number.
var asNumbers = sNumbers.split(":");
// If the line contains only 1 number,nothing to do for this line.
if (asNumbers == null) continue;
// Convert the number strings into integers and sum them.
var nSum = 0;
for (var nNumber = 0; nNumber < asNumbers.length; nNumber++ ) {
// Skip empty strings caused by ::between the numbers.
if (asNumbers[nNumber].length == 0) continue;
nSum += parseInt(asNumbers[nNumber],10);
}
// Build new line with fixed text and the sum converted to a decimal number string.
asLines[nIndex] = sText + nSum.toString(10);
}
// Rebuild the block with the modified lines in user clipboard 9.
UltraEdit.clipboardContent = asLines.join(sLineTerm);
// Paste the block over the still selected lines.
UltraEdit.activeDocument.paste();
} while (UltraEdit.activeDocument.isEof() == false);
// Clear user clipboard 9 and select Windows clipboard.
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
}
直接用 正则表达式 似乎不行.有两种途径:
1.把":"替换成制表符,然后整体拷贝到Excel中,在某列(如第6列)中写公式=b1+c1+d1+e1+f1,下拉适用所有,得出一样的结果.
2.用ultraedit的script也可以实现.
if (UltraEdit.document.length > 0) { // Is any file opened?
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.ueReOn();
/* Verify the line termination of the last line of the file
and insert one if the last line has no line termination.*/
UltraEdit.activeDocument.bottom();
if (UltraEdit.activeDocument.isColNumGt(1)) {
UltraEdit.activeDocument.insertLine();
if (UltraEdit.activeDocument.isColNumGt(1)) {
UltraEdit.activeDocument.deleteToStartOfLine();
}
}
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.trimTrailingSpaces();
// Define line terminator type by default for DOS.If the version of
// UE/UES has support for the line terminator property,use it to set
// the line terminator string according to the value of this property.
var sLineTerm = "\r\n";
if (typeof(UltraEdit.activeDocument.lineTerminator) == "number") {
if (UltraEdit.activeDocument.lineTerminator == 1) {
sLineTerm = "\n"; // UNIX file not converted to DOS.
} // Ignore older versions of UltraEdit and MAC files for this
} // script and use in all other cases also DOS line terminators.
UltraEdit.selectClipboard(9);
// Process entire file in blocks of 10000 lines to end of file.
var nLineNum = 1;
do {
nLineNum += 10000;
UltraEdit.activeDocument.gotoLineSelect(nLineNum,1);
if (!UltraEdit.activeDocument.isSel()) break;
var asLines = UltraEdit.activeDocument.selection.split(sLineTerm);
// Process each line of the selected block.
for (var nIndex = 0; nIndex < asLines.length; nIndex++ ) {
// Find first character of a sequence of colon delimited numbers at end of the line.
var nNumberPos = asLines[nIndex].search(/(?:\d+:*)+$/);
// If no number found,for example a blank line,skip the line.
if (nNumberPos < 0) continue;
// Split the line into fixed text and the numbers as string.
var sText = asLines[nIndex].substr(0,nNumberPos);
var sNumbers = asLines[nIndex].substr(nNumberPos);
// Split the numbers string up into an array of strings each with a number.
var asNumbers = sNumbers.split(":");
// If the line contains only 1 number,nothing to do for this line.
if (asNumbers == null) continue;
// Convert the number strings into integers and sum them.
var nSum = 0;
for (var nNumber = 0; nNumber < asNumbers.length; nNumber++ ) {
// Skip empty strings caused by ::between the numbers.
if (asNumbers[nNumber].length == 0) continue;
nSum += parseInt(asNumbers[nNumber],10);
}
// Build new line with fixed text and the sum converted to a decimal number string.
asLines[nIndex] = sText + nSum.toString(10);
}
// Rebuild the block with the modified lines in user clipboard 9.
UltraEdit.clipboardContent = asLines.join(sLineTerm);
// Paste the block over the still selected lines.
UltraEdit.activeDocument.paste();
} while (UltraEdit.activeDocument.isEof() == false);
// Clear user clipboard 9 and select Windows clipboard.
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
}
看了Ultraedit数字求和有上...的网友还看了以下:
设{W(t),t>=0}是参数为d的平方的(打不出来那个方差的符号,W(t)-aW(t-h)t>= 2020-05-13 …
海运中经常会说多少T(不是吨,而是英文字母T)这个多少T是指什么?还有也会说这个船有多少T(英文字 2020-05-16 …
诗句帮忙想一句话,12字以内不包含标点符号,里面包含强燕两个字,表示爱情美诗句帮忙想一句话,12字 2020-05-21 …
pascal帮帮忙判断回文串二读入一行字符,以#结束。这些字符只包含大写字母、小写字母和数字,总长 2020-06-09 …
200分真心讨教高数定积分知识假定函数f(X)以T为周期即对于任意的实数x有f(x+t)=f(x) 2020-07-09 …
与原文语句相符的画“T”,不相符的画“F”其亦欲推其事,以勉其学者邪?() 2020-11-10 …
什么样的两个ASCII字符可以合并成一个汉字?在WINHEX里看一个包含汉字和半角字符的TXT的时候 2020-11-25 …
用数字字母符号可以组成哪些简单的表情啊?用数字和字母可以组成哪些简单的表情符号哇?T-T.…越多越好 2020-11-29 …
有几个关于排列和组合的题目不会,1)某电脑系统的每名用户都含有一个含有6个字符的密码,而每个字符可以 2020-12-02 …
以f开头以w结尾的,以l开头以t结尾的,以r开头以d结尾的,以n开头以t结尾的单词4个单词中间填的字 2021-02-03 …