Author Topic: Removing CR/LF characters  (Read 6752 times)

Offline devenh

  • Sr. Member
  • ****
  • Posts: 435
    • View Profile
Removing CR/LF characters
« on: March 23, 2010, 10:01:32 PM »
I have a large number of files where the last characters in the headline field are CR/LF.  Is there a way I can remove the CR/LF with Find & Replace or via the {headline} variable?

Deven

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 25020
    • View Profile
    • Camera Bits, Inc.
Re: Removing CR/LF characters
« Reply #1 on: March 23, 2010, 10:21:43 PM »
Deven,

I have a large number of files where the last characters in the headline field are CR/LF.  Is there a way I can remove the CR/LF with Find & Replace or via the {headline} variable?

Is this only occurring in the Headline field?  If so, you could just apply an IPTC Stationery pad using {headline:-1} (or perhaps -2) in the Headline field.

Do a test on one selected image to make sure you've got it right.

HTH,

-Kirk

Offline devenh

  • Sr. Member
  • ****
  • Posts: 435
    • View Profile
Re: Removing CR/LF characters
« Reply #2 on: March 24, 2010, 07:20:05 AM »
Kirk,

Doesn't {headline:-1} just return the last character of the field?  What I want to do is remove the last character of the field.

Example (note * represents a CR), the headline field contains

John*

What I want is

John

Since the length of each name varies, what I need is something like:

{headline:0:length of headline minus one}

Deven

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 25020
    • View Profile
    • Camera Bits, Inc.
Re: Removing CR/LF characters
« Reply #3 on: March 24, 2010, 07:28:27 AM »
Deven,

Doesn't {headline:-1} just return the last character of the field?  What I want to do is remove the last character of the field.

Example (note * represents a CR), the headline field contains

John*

What I want is

John

Since the length of each name varies, what I need is something like:

{headline:0:length of headline minus one}

You're right. You'll want to use {headline:0,-1} instead.  From the manual:

Substring extraction can be used to ‘extract’ a range of characters from an image variable so they can be used as normal variables in other fields throughout Photo Mechanic.
The format is:
{variable:index,count:conversion} or {variable:index:conversion}
In either case, <:conversion> is optional
<index> Sets the point in the string at which the operation starts - zero (0) will include all characters, 1 will ignore the first character etc. This value can be positive
or negative. Negative numbers count back from the end of the string, positive numbers count from the beginning.
<count> to extract <count> characters from <index>. <count> may also be omitted altogether which indicates extracting the substring from <index> position to the end of the string.
<conversion> may be one of the following types or may be omitted altogether:
“lc” perform lower-case conversion of all applicable characters
“UC” perform upper-case conversion of all applicable characters
“PC” perform Proper Name case conversion
Here are some examples:
Let’s say {filenamebase} is DSC_1234
Then:
{filenamebase:0,3} yields: DSC
{filenamebase:-4,4} yields: 1234
{filenamebase:-4} yields: 1234
{filenamebase:2,3} yields: C_1
{filenamebase:0:lc} yields: dsc_1234
{filenamebase:0:PC} yields: Dsc_1234

-Kirk

Offline devenh

  • Sr. Member
  • ****
  • Posts: 435
    • View Profile
Re: Removing CR/LF characters
« Reply #4 on: March 24, 2010, 07:50:39 AM »
Kirk,

You know I actually read the manual and I didn't see this.  The manual only talks about negative index values, it does not mention negative count values.

As a conversion option, it might be nice to have a TRIM and CLEAN option like Excel does (Trim removes leading and trailing white space, Clean removes non printable characters).

Deven

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 25020
    • View Profile
    • Camera Bits, Inc.
Re: Removing CR/LF characters
« Reply #5 on: March 24, 2010, 09:08:53 AM »
Deven,

You know I actually read the manual and I didn't see this.  The manual only talks about negative index values, it does not mention negative count values.

As a conversion option, it might be nice to have a TRIM and CLEAN option like Excel does (Trim removes leading and trailing white space, Clean removes non printable characters).

It could be more clear.  The example in the manual:

{filenamebase:-4} yields: 1234

Kind of hints at that capability, but I'll add some additional treatment on the issue.

-Kirk


Offline argebee

  • Newcomer
  • *
  • Posts: 1
    • View Profile
Re: Removing CR/LF characters
« Reply #6 on: March 26, 2010, 03:09:08 PM »
I too needed to do something like this. I wanted to snip off the last character in the IPTC caption field and append a string. Unfortunately, it does not appear to be possible to use variable substrings to write to the same field the variable is read from. The manual confirms this, although a little too subtly for me to catch it on the first read (asterisks added for emphasis):

"Substring extraction can be used to ‘extract’ a range of characters from an image variable so they can be used as normal variables in ***other*** fields throughout Photo Mechanic."