IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Splitting a string by a maximum of 30 characters, but keeping 'whole words' Options · View
Ash
Posted: Friday, October 30, 2020 12:35:59 AM
Rank: Member

Joined: 8/21/2019
Posts: 10
Location: United Kingdom
I'll try to explain what I'm attempting to do.

I have a 'string' of words, and this string can be between 10 and 200 characters long.

I would like to find a way of splitting this string, but a maximum of 30 characters. But the string should not split in the middle of a word.

For this example, I've taken the below sentences from a 'random sentence generator' website

The fact that there's a stairway to heaven and a highway to hell explains life well. You can't compare apples and oranges, but what about bananas and plantains? As he looked out the window, he saw a clown walk by.


I will now mark out where the 30 character splits are:

The fact that there's a stairw|ay to heaven and a highway to |hell explains life well. You c|an't compare apples and orange|s, but what about bananas and |plantains? As he looked out th|e window, he saw a clown walk |by.


This is a problem, because the splits will looks like this:

1. The fact that there's a stairw
2. ay to heaven and a highway to
3. hell explains life well. You c
4. an't compare apples and orange
5. s, but what about bananas and
6. plantains? As he looked out th
7. e window, he saw a clown walk
8. by.

What I would like to do, is split these strings at the 'space' before the word thats being cut into (if that makes sense).... So like this:

The fact that there's a |stairway to heaven and a |highway to hell explains life |well. You can't compare apples |and oranges, but what about |bananas and plantains? As he |looked out the window, he saw |a clown walk by.


Resulting in the following splits:

1. The fact that there's a
2. stairway to heaven and a
3. highway to hell explains life
4. well. You can't compare apples
5. and oranges, but what about
6. bananas and plantains? As he
7. looked out the window, he saw
8. a clown walk by.

I hope this makes sense.

If someone can show me how to do this within MapForce that would be great.

Unfortunately I don't have any 'real' dummy data to hand, but essentially I'll be taking a string / splitting it (as per the example above) / and then placing it within an XML file.
But I just need to know how to achieve the above effect.

I've read that RegEx might be able to do it and I tried to achieve this by using RegEx... But I can't seem to get the RegEx to work? I don't know anything about RegEx, so I'm unable to debug it.


K101
Posted: Friday, October 30, 2020 1:04:35 PM
Rank: Advanced Member

Joined: 2/27/2009
Posts: 564
I recall seeing a similar post about this beforeā€¦
K101
Posted: Friday, October 30, 2020 1:43:57 PM
Rank: Advanced Member

Joined: 2/27/2009
Posts: 564
Have a look at this old topic.
Ash
Posted: Friday, October 30, 2020 6:12:48 PM
Rank: Member

Joined: 8/21/2019
Posts: 10
Location: United Kingdom
K101 wrote:
Have a look at this old topic.


That solution works perfectly K101 thank you very much!
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.