trim characters length of value after second comma
-
Well you guys are my last help or I face a night of hard work so here goes.
Essentially the question I need help with is simple; the value that appears between the second and third comma on each line starting with a set value, need to be trimmed to a max of 35.
example
ARC,value1,value2,value3,value,4,value5
the actual character string in Value2 should be trimmed down on the right side so that the overall length does not exceed 35 characters. Each sentence would start with the leading character ARC, if that is of any help.
is this possible in Notepass++ ?
-
@Lucius-Balfour
It is possible, but you haven’t given us much to work with. The primary issue (as I see it) is that the values could also contain a comma and then they would likely be contained within quotes. This is normally how a CSV file (which seems to be the type of data you are showing) will appear.Are you able to show some example data (as long as not sensitive/confidential information)? When doing so, please read the FAQ post called Template for Search/Replace Questions. It is necessary to insert examples in the correct manner as otherwise the posting engine can alter the data.
In your case if quotes are included then is is very necessary as quotes are one of the most common issues we see with example data.
Terry
-
@Lucius-Balfour said in trim characters length of value after second comma:
need to be trimmed to a max of 35.
If you mean that it should change 39 or 123 to 35, but leave 12 as 12, then Notepad++ cannot do that natively – at least, not in the generic sense. If your hard limit of 35 will never change, then a regex could be developed that would only do the replacement if an integer from 0 to 35 were not found in the value2 field. But if today you want the cutoff to be 35, but tomorrow you want it to be 123, and on Friday you want it to be 13, then either you’d have to redo your regex every time, or you’d need a scripting solution to bring in “math” features, per this FAQ.
If all you will need is for a limit of 35, and that limit will never change, then as long as you answer @Terry-R’s followup, he or someone else here should be able to come up with a regex that will meet your needs.
-
Hi Terry thanks so much for responding.
Typically a line of data would look as follows
ARC,1234567898765,john paul ringo mick keith michael gabriel pete grace mark,12345,67892, 99922288822
The area of interest is the bold section, which contains only letters, no funny characters, which needs to be trimmed down from the right to a max of 35 characters .
-
@PeterJones Thanks Peter, no i am not looking to change an actual value, just a way to reduce the number of characters between 2nd and 3rd comma to 35, in each line that starts with ARC.
-
@Lucius-Balfour said in trim characters length of value after second comma:
Thanks Peter, no i am not looking to change an actual value, just a way to reduce the number of characters
Sorry, somehow, I misread, and thought you were talking about math (trimming down to a value between 0 and 35). Yes, length is easier.
-
@Lucius-Balfour said in trim characters length of value after second comma:
which needs to be trimmed down from the right to a max of 35 characters
Thus, you’d want to achieve:
ARC,1234567898765,john paul ringo mick keith michael ,12345,67892, 99922288822
-
@Alan-Kilborn Correct!
-
@Lucius-Balfour said in trim characters length of value after second comma:
The area of interest is the bold section, which contains only letters, no funny characters, which needs to be trimmed down from the right to a max of 35 characters
My solution is a regular expression which means the search mode must be set to regular expression.
Find What:^(ARC,[^,]+,[^,]{1,35})[^,]*
Replace With:${1}
Give this a try on a copy of your data. As you have only supplied 1 dummy example line and that wasn’t within the code block (as I requested, see other’s examples as supplied) there is a chance you may still have problems.
Terry
-
@Terry-R Thank you so much, apologies for the late reply, but this really did help. Thank you for taking the time to help!