去除csv檔案單元格內的逗號

2021-07-04 08:17:33 字數 1075 閱讀 4662

csv檔案協議為 : 如果單元格內有逗號,則該單元格外部用引號括起來,如果單元格內部有引號,則單元格外部用引號括起來,同時單元格內部的引號前面再加上引號

比如 : csv中的一行為 a,(b,c),d」c,e

實際儲存的字元為: a,」(b,c)」,」d」「c」,e

演算法思路是基於這個規則,找到從字串的開始進行遍歷,找到兩組引號數量一致時,對引號內的逗號進行替換,然後接著往下遍歷,該演算法有乙個漏洞,就是如果csv某一行存放值為 : 「,」,」 即有兩個單元格只存放了乙個引號,則該演算法為錯誤的認為分隔符逗號是單元格內的,目前還沒想到什麼好的方法解決.

//替換逗號的原則,兩組引號之間,並且兩組引號的個數相同,一組引號遍歷完成後,跳到一組

private

static string trimquote(string source)

char array = source.tochararray();

int len = array.length;

intindex = 0;

stringbuilder builder = new stringbuilder();

while (index

< len)

int squotecount = 0;

while (index

< len && array[index].equals('"'))

int start = index;

while (index

< len && !array[index].equals('"'))

int equotecount = 0;

while (index

< len && array[index].equals('"'))

int end = index;

if (squotecount > 0 && squotecount == equotecount)

pos++;}}

}string cc = new string(array);

return cc.replace("#", "");

}

table的寬度,單元格內換行問題

table的寬度,單元格內換行問題 選擇自 chnking 的 blog 一.要想固定table的總的寬度和每列的寬度 或在指令碼中 this.style.tablelayout fixed html scripting object.style.tablelayout slayout 可能的值 s...

table的寬度,單元格內換行問題

選擇自 chnking 的 blog 一.要想固定table的總的寬度和每列的寬度 或在指令碼中 this.style.tablelayout fixed html scripting object.style.tablelayout slayout 可能的值 slayout string設定或獲取...

table的寬度,單元格內換行問題

一.要想固定table的總的寬度和每列的寬度 或在指令碼中 this.style.tablelayout fixed html scriptingobject.style.tablelayout slayout 可能的值 slayout string設定或獲取下面的值 auto 預設設定.列寬將設定...