# Spliting a var by length

**URL:** <https://forum.kirupa.com/t/spliting-a-var-by-length/122625>\
**Category:** Uncategorized\
**Created:** [September 15, 2004, 1:48pm UTC](https://forum.kirupa.com/t/spliting-a-var-by-length/122625 "2004-09-15T13:48:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![VoS](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@VoS](https://forum.kirupa.com/u/VoS)\
**Post date:** [September 15, 2004, 1:48pm UTC](https://forum.kirupa.com/t/spliting-a-var-by-length/122625/1 "2004-09-15T13:48:46Z")

</div>

hey…  
id like some help with a coding problem =)  
i have a var lets say ‘x’  
x=“i like cheese and want to eat it everyday”  
i want to split the var x by every 10’th character, assuming the 10 chracter is not in the middle of a word , then i want it to split it before that so that no words are not cut out…  
ex:  
x=“i like cheese and want to eat it everyday”  
arr[1]="i like " 7chars causs 10th char was inside ‘cheese’ and spliting of words is not allowed  
arr[2]="cheese and " 10 chars exactly , splits at space  
arr[3]="want to " 8 chars 10th char inside eat … u get the idea by now i hope =)  
arr[4]="eat it "  
arr[5]=“everyday”  
so its splitting the variable every 10th character… if the 10th chracter is a space, if it is not it backs up to the previous space and for the next array slot starts from there

```
hope this makes sense =)

```

been trying to figure this out for a while now with no luck, hoping the geniuses at kirupa can 😉
