- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Removing the end of a string of variable length
Hello all,
I have a column :Protocol which contains strings of variable length in the format Character, Nominal. I've added some examples below. I am trying to remove the last 4 characters of the string from the column, and keep everything else. The last 4 characters are always one of: -001, -002, -003, or -004. I have tried to accomplish this using Word(), and Substr() but am unable to get it to work:
Protocol
AAA-BB-1234-19-001
AAAA-B-18-002
AA-BBB-123-18-003
AA-B-CC-1001-19-002
This is what I want the column to look like for those 4 rows:
Protocol
AAA-BB-1234-19
AAAA-B-18
AA-BBB-123-18
AA-B-CC-1001-19
I have tried to accomplish this using the Word() functions as follows:
For Each Row(
:Protocol = Word(1, :Protocol, "00")
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Removing the end of a string of variable length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Removing the end of a string of variable length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Removing the end of a string of variable length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Removing the end of a string of variable length
I agree with @David_Burnham , you can get results by directly using left, if you really wanna use word, maybe you can refer to this one below (I also attached data table in attachment):
Names Default To Here( 1 );
Clear Log();
dt = Current Data Table();
new_col = dt << New Column( "Trimmed Protocol",
character,
formula( Word( [1 -2], :Protocol, "-" ) )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Removing the end of a string of variable length
I thought of using the Left() function, too. Here is my take:
Names Default to Here( 1 );
string = "AAA-BB-1234-19-001";
Left( string, Contains( string, "00") - 2 );
I recommend that you select Help > Scripting Index and select Functions > Character. There is a lot of built-in support for manipulating character strings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content