Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

break up string by 255 characters

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hi
If I want to take a string that is large lets say 410 characters. A database char field can only hold 255. how can I split up the string by 255. The split command will not work because you need a dealimiter. I do not want to go by a dealimiter but by number of charaters. Any help is greatly apprecitated.

 
Try this, I haven't tested it...
(if you have any syntax problems see
Code:
function split(mystring){
var string1 = mystring;
var string2;

for (i=0;i=255;i++){
	string2 = string2 + string1.charAt(i);
}
}

this could be modified to get the next 255 chars aswell if you want...

let me know how you get on.

Mitch
 
left will not work because that will only get the first 255 char from left, i would then need to use mid(string, 256, 510) and then do some programming to see if I need another mid or if I can just do a right. Im am trying to avoid as much coding as possible.
 
I don't see how you can do it without a loop. By the way, some database fields are limited to 254, not 255 characters. Here is a sample loop copying it into arrays which are simpler to dimension:

Code:
Dim i, myarray(50)

For i = 1 to 50
    ' 50 * 254 = 12,700 chars max in string
    ' increase or decrease array size as desired
    myarray(i)=""  'init all as empty string
Next

For i=1 to len(mystring) Step 254
    myarray(i)=mid(mystring,i,i+253)
Next
 
I keep getting Typy Mismatch on this line:
myarray(i)="" 'init all as empty String
any idea?
 
I got past that error, but this does not work at all. I keep getting out of subscript error. I pu i-1 in the step 254 step and that does not work.
 
Code:
i = 0
While Len(mystring) > 0
  myarray(i) = Left(mystring, 254)
  i = i + 1
  mystring = Mid(mystring , 255)
Wend

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top