I want to split a large chunk of data into 32 char meaningful strings.
Intrepid Air and Space Museum of ny 46th St And 12th Ave Pier 86 New York City, NY 10036 into 3 chunks without breaking a work.
Intrepid Air and Space Museum, of ny 46th St And 12th Ave Pier, 86 New York City NY 10036
INPUT : Impact Christian Church of Woodland Park Colorado Scott Park
EXPECTED OUTPUT:
Impact Christian Church of
Woodland Park Colorado Scott Park
@pchi tricky problem.
This should satisfy what you're after using Regex. You can see the solution visually here: https://regex101.com/r/ZAcStF/2
(.{1,32}\b\S*)
Explanation:
The combined expression ensures that we finish capturing the whole word without restricting the character count strictly to 32 characters.
Workflow attached, and here's a sneak peak:
Any questions, @ me so I get notified.
All the best,
BS
You do have two conflicting pieces of logic and you're trying to tailor certain solutions to certain scenarios. If only things were that easy 😂. You need to settle on the following, if you're 32 character is mid-way through a word, you capture this word in the current group or you let it move across to the next group.
For example,
You can see the different shades of blue in the picture above. This indicates the different grouping every 32 letters, and if it's mid-way through a word it moves it to the next group. In the first example you provided, "of" moves into the next group. In the second example you provided "Park" moves into the current group.
You can't have it both ways.
The solution I provided in the workflow ensures, if it's mid-way through a word, that it will capture that word in the group it's currently in.
Feel free to use this Regex below, if you want to move the word to the next group, if it's midway through.
.{1,32}\b
All the best,
BS
I dont want break a word mid way, yet fit them into 32 byte chunks.
INPUT String:
Vibrant—A Christian Church Mechanicsburg, Pa.
Expected Result:
Vibrant—A Christian
Church Mechanicsburg, Pa.
rather cutting it down midway.
Vibrant—A Christian Church Mech
anicsburg, Pa.
I will try your solution and will let you know.
thanks
when I tried your example, this is the result I got. Here the first column is 41 chars.
Vibrant—A Christian Church Mechanicsburg|||, Pa|||.
expecting
Vibrant—A Christian Church |Mechanicsburg,pa|||.