BookmarkSubscribeSubscribe to RSS Feed
NKH

Community Member

Joined:

Aug 9, 2018

Altering text with arbitrary characters

Hi, I need to change the name of columns. Specifically, I need to remove any @ followed by arbitrary 6 digit numbers. To make it clear, jhsj@ksjdskj@123456 need to change to jhsj@ksjdskj.  There are lots of 6digit numbers and all different. Any idea how I should do this?

 

This is the piece of code I have so far:

 

dt = current data table();
colnames = dt << get column names("string");
for(i=1,i<=n items(colnames),i++,
??????????????
);
1 REPLY
Highlighted
ms

Super User

Joined:

Jun 23, 2011

Re: Altering text with arbitrary characters

Try Regex() to find and delete any occurences of "@xxxxxx" in the column names. 

 

dt = Current Data Table();
colnames = dt << get column names("string");
For(i = 1, i <= N Items(colnames), i++,
    Column(dt, i) << set name(
        Regex(colnames[i], "(.+)@\d{6}(.*)", "\1\2", GLOBALREPLACE)
    )
);