Skip to main content
Solved

How do you find spaces by counting character intervals ?


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.

View original
Did this help you find an answer to your question?

7 replies

david_r
Celebrity
  • 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+28
  • Contributor
  • 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
  • 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
  • June 10, 2020
jdh wrote:

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
  • June 10, 2020
jdh wrote:

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+28
  • Contributor
  • June 10, 2020
david_r wrote:

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
  • June 10, 2020
jdh wrote:

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

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

)

Devious regex... ;-)


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings