If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > concatenate a string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-27-11, 10:04
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
concatenate a string

Ok a slightly odd question, but what I need to know is how to concatenate a string.

I have a string of numbers which could range from 10 to perhaps 255 characters (probably more).

Lets say I have a 10 character string which is "0123456789"

What I would like to be able to do is concatenate this at every 3rd interval so I achieve

012 345 678 9

Is this possible and does someone have a solution?
Reply With Quote
  #2 (permalink)  
Old 07-27-11, 10:13
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
write a function that chops the string into ndigit elements
..should be something similar to:-

Code:
public function PadString (strString as String, NoChars as integer) as string
dim NoItertations as integer 'this will be the number of times we go through the source
PadString = "" 'will be the return value from the function
NoIterations = length(strString)\NoChars 'find out how many iterations there are in the source
for iLoop = 1 to NoIterations step NoChars
  PadString = padString & mid(strString, iLoop, iLoop+NoChars) & " "
next iLoop
end function
but the above is untested, unporven air code, just made up on the fly
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 07-27-11, 10:17
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
On the fly? amazing...

It looks ok but can you explain what 'NoChars' is?
Reply With Quote
  #4 (permalink)  
Old 07-27-11, 10:28
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
Healdem sorry I figured it meant 3 but couldn't be sure.

Your function works perfectly with the exception of

Code:
...strString, iLoop, iLoop+NoChars) & " "
With this it seemed to exponentially grow... i.e. the first group was 4 letters long, then it was 7 then it was 10...

I adjusted iLoop + NoChars and it worked so thank you!

Code:
...strString, iLoop, NoChars) & " "
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On