remove part of a string (contingent upon number of periods within that string)?<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />I have a column with strings of varying length. All strings have 1 semicolon separating the first and last part of the string.
some strings with no 'periods':
_______________;______
some strings with 1 period
______.______;_______
some strings with 2 periods
___._______._____;_________
I want to create a new column and populate it with the string of interest with the following conditions:
- IF a string contains exactly 2 periods, I want to remove everything from the second period up to the semicolon
- example: "before1st.after1st.after2nd;afterSemiColon" would return "before1st.after1st;afterSemiColon"
- ELSE, i just want to leave the string alone (no changes)
I'm having trouble with this since the length of characters between each period can vary
any help on the best way to achieve this would be greatly appreciated! thank you!
Re: remove part of a string (contingent upon number of periods within that string)?col = Column( "Column" );
new_col = New Column( "New Column", character );
For Each Row(
w = Words( col[], ".;" );
If( N Items( w ) == 4,
new_col[] = w[1] || "." || w[2] || ";" || w[4],
new_col[] = col[]
);
);
Re: remove part of a string (contingent upon number of periods within that string)?thank you MS! this works great.
How would I modify this so that instead of editing the contents of "Column", it instead populates a new column with the new edited string?
Re: remove part of a string (contingent upon number of periods within that string)?Assuming there are no periods after the semicolon, this script should work:
(Change "Column" to the name of the column with strings)
col = Column( "Column" );
For Each Row(
w = Words( col[], ".;" );
If( N Items( w ) == 4,
col[] = w[1] || "." || w[2] || ";" || w[4]
);
);