Dynamically Seperate a string...

Results 1 to 2 of 2

Thread: Dynamically Seperate a string...

  1. #1
    Join Date
    Dec 1969

    Default Dynamically Seperate a string...

    I&#039;ve been tasked with coming up with a way to create a function that will take a number, delimiter and seperating number to allow someone to feed the function a number like so...<BR><BR>123456789101112<BR><BR>a delimiter "-"<BR><BR>a seperating number 4<BR><BR>Then have the function return:<BR><BR>1234-5678-9101-112<BR><BR>The problem I&#039;m having is that the number can vary in length, the delimiter can vary in type ("-", ".", " ", etc), and the seperating number can vary in length...<BR><BR>Does anyone know how to dynamically do this..<BR><BR>Any help would be great...<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default So you want to write a function...

    ...that does this?<BR><BR>One idea (untested):<BR><BR>function parse_string(in_string, in_delimiter, in_separator)<BR> rem in_string and in_delimiter are strings, in_separator is a number<BR> string_length = len(in_string)<BR> output = ""<BR> for i = 1 to string_length<BR> one_char = mid(in_string,i,1)<BR> output = output + one_char<BR> if i mod in_separator = 0 then<BR> output = output + in_delimiter<BR> end if<BR> next<BR> parse_string = output<BR>end function<BR><BR>Then:<BR><BR>Response.Write(parse_ string(&#039;123456789101112&#039;,&#039;-&#039;,4))<BR><BR>Or whatever you want to do with the result.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts