如何從資料集中的列名中刪除前導字元 (::) 和結束字元 (;;)嘿,你能給我一個建議,如何刪除開頭的 :: 和 ;; 等某些符號嗎?位於列名稱的末尾(如果有)。
例子:
::列名;; --> 列名
::列名::XYZ;ABC;; --> 列名::XYZ;ABC
123::ColumName --> 沒有變化 123::ColumName
自動化和腳本編寫視窗回覆:如何從資料集中的列名中刪除前導字元 (::) 和結束字元 (;;)命名的幾個附加選項
// Option1, using Starts With, Ends With and Substr
If(Starts With(col_name, "::"),
col_name = Substr(col_name, 3);
);
If(Ends With(col_name, ";;"),
col_name = Substr(col_name, 1, Length(col_name) - 2);
);
不確定這是否適用於所有情況
// Option2, using Regex
regex_pattern = "(?:^::)(.*)(?:;;$)";
Regex(col_name, regex_pattern, "\1");
回覆:如何從資料集中的列名中刪除前導字元 (::) 和結束字元 (;;)這是一個簡單的腳本,可以完成您想要的操作
Names Default To Here( 1 );
dt = Current Data Table();
For( i = 1, i <= N Cols( dt ), i++,
theName = Column( dt, i ) << get name;
If( Left( theName, 2 ) == "::",
theName = Substr( theName, 3 )
);
If( Right( theName, 2 ) == "::",
theName = Substr( theName, 1, Length( theName ) - 2 )
);
Column( dt, i ) << set name( theName );
);