Skip to main content
Solved

How do you find spaces by counting character intervals ?

  • June 9, 2020
  • 7 replies
  • 77 views

Hello everybody,

 

 

My problem : I have a "Description" attribute which contains text with length variable. The lenght is greater than 2000 characters. For each feature of the "Description" attribute, I want to replace all spaces after every 80 characters with "LF" (new line).

 

 

So I thank use StringReplacer to write a regular expression to calculate 80 characters intervals and identify the space after each 80 characters. Then I could have replace this by LF.

 

 

I helped myself with these topics on the forum:

 

- https://knowledge.safe.com/questions/51531/how-do-i-find-the-first-space-after-the-19th-chara.html

 

- https://knowledge.safe.com/questions/51514/splitting-attributes-by-number-of-words.html

 

- https://knowledge.safe.com/questions/40715/count-the-number-of-characters-and-numbers-in-a-gi.html

 

 

But I d'ont success it. Maybe I don't really understand explanations....

 

 

Do you have any leads ?

 

 

Thank you so much !

 

 

 

 

 

Best answer by david_r

You can use the TextWrapper custom transformer from the FME Hub, followed by a ListConcatenator to insert a LF between all the resulting list items.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

david_r
Celebrity
  • 8392 replies
  • Best Answer
  • June 9, 2020

You can use the TextWrapper custom transformer from the FME Hub, followed by a ListConcatenator to insert a LF between all the resulting list items.


jdh
Contributor
Forum|alt.badge.img+37
  • Contributor
  • 2002 replies
  • June 9, 2020

Couldn't you just use Takashi's solution in the previous example, creating an attribute with the following:

@ReplaceRegEx(@Value(text),(.{80,}?)\\s,\\1

)

where text is the name of the attribute containing the original string?


  • Author
  • 2 replies
  • June 10, 2020

Thank you david_r and jdh for your help ! I don't test your proposition jdb but I keep your idea !

 

dvid_r your solution do what I want perfectly ! Thank you !!

 

 

 

 

 


  • Author
  • 2 replies
  • June 10, 2020

Couldn't you just use Takashi's solution in the previous example, creating an attribute with the following:

@ReplaceRegEx(@Value(text),(.{80,}?)\\s,\\1

)

where text is the name of the attribute containing the original string?

Thank you jdh for your help ! I don't test your proposition jdb but I keep your idea !


david_r
Celebrity
  • 8392 replies
  • June 10, 2020

Couldn't you just use Takashi's solution in the previous example, creating an attribute with the following:

@ReplaceRegEx(@Value(text),(.{80,}?)\\s,\\1

)

where text is the name of the attribute containing the original string?

Funny, doesn't work for me. Rather than inserting newlines it seems to simply remove the space between the words every ~80 characters. Tested with FME 2020: regex_wordwrap.fmwt


jdh
Contributor
Forum|alt.badge.img+37
  • Contributor
  • 2002 replies
  • June 10, 2020

Funny, doesn't work for me. Rather than inserting newlines it seems to simply remove the space between the words every ~80 characters. Tested with FME 2020: regex_wordwrap.fmwt

Bad formatting on my part. Put the closing parenthesis on a new line

@ReplaceRegEx(@Value(text),(.{80,}?)\\s,\\1

)


david_r
Celebrity
  • 8392 replies
  • June 10, 2020

Bad formatting on my part. Put the closing parenthesis on a new line

@ReplaceRegEx(@Value(text),(.{80,}?)\\s,\\1

)

Devious regex... ;-)