Bringing the Lovely VBScript Split Function into Delphi with a Custom Function
Posted by Daniel - 2,168 Views
It was a very old idea that I want to be able to perform the process carried out by the VBScript Split Function with Delphi. I had done it once but only capable of doing the split process with only one character as the delimiter, if I want to split a series of strings by two or more character as the delimiter, it didn’t work. This is the update, now I can perform the Split process with more than one character as the delimiter.
Before you get confused by what the Split Function does, let me explain: Split Function which is found as a built in function on the Visual Basic family languages will slice a strings based on a character delimiter specified and then will return an array containing each pieces from the slice process.
For example if you run this code:
Then the arrSplit will contains 3 elements:
arrSplit(0)=”a”
arrSplit(1)=”b”
arrSplit(2)=”c”
That kind of function does not available as a built-in function in Delphi (am I wrong?), but I want to be able to perform such process with Delphi so as usual, I created my own function, and here is the code:
var i : integer;
s : string;
arrString: TStringList;
begin
arrString := TStringList.Create;
s := ”;
i := 1;
repeat
begin
if Copy(source,i,Length(delimiter)) <> delimiter then
begin
s := s + Copy(source,i,1);
i := i + 1;
end
else
begin
arrString.Add(s);
s := ”;
i := i + Length(delimiter);
end;
end
until i > Length(source);
if s <> ” then arrString.Add(s);
result := arrString;
end;
MySplit Function will slice the string passed as the source parameter based on the delimiter character specified and then will return the resulting array as a stringlist.
A demo is included with this article. You can download the demo project then have it tested to see how the function works.
If you only need to split strings with one character as the delimiter, you may also consider the function from Zarko Gajic here - it’s neat and brilliant.
Download the demo project (8 KB)
__________________________
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- FlatStyle Delphi controls (Flat controls for your Delphi application)
- Delphi SMSCodec (SMS Processing Component)
- PinoezProgramRun (Running external program from Delphi)
- An example: Using CPort Delphi Component to read data from your cellphone
Related posts brought to you by Yet Another Related Posts Plugin.
Latest from Programming
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- Free Softwares to help you learn Regular Expression or to enhance your RegEx skill
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
2 Responses to “Bringing the Lovely VBScript Split Function into Delphi with a Custom Function”
Leave a Reply
Latest Blog Entries
- Sweet Home 3D, a free home design software
- 26x Optical Zoom on a Compact Digital Camera?
- Windows 7 Release Candidate is now available
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- The Lack of Chances is the Source of Poverty, Can we make a different?
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
Categories
Neighbours and Friends
- Anti Teori
- Busby SEO Test Page
- Deny Sri
- Digital Media Convert
- Freeware Maniac
- Oeroek
- RidhoCyber
- Suraja Web
Comments - Thanks Guys :)
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
Marlena Albu: Super Blog, Dude! I am constantly on the watch for new and interesting sites and postings about audio equipment… which is what...
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.
Sean: This is a great piece of code and thanks for adding the updates. Sean’s last blog post: Not All Text Message Marketing Is Created...
rodhy: Thank for your code, it very usefull for me. best regard.
Most Popular Entries
- Passing arguments to your VB.NET console application
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- An example: Using CPort Delphi Component to read data from your cellphone
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
Software Collections
- Sweet Home 3D, a free home design software
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
- TCPView for Windows, Tool to check TCP and UDP Connections on your system
- The Code Snippet Plugin, my favourite syntax highlighter plugin for WordPress
Blogging Related Stuff
- Change the WordPress permalink structure to the best format, and yes it’s a little bit scary :D
- Something is wrong, the Google Search Result from my blog looks bad, don’t laugh please :D
- Several tips to reduce Blog Noise, especially when your blog covers more than one niche
- How to remove your indexed pages or even your entire site from Google and Yahoo!


















April 24th, 2009 at 6:08 am
Interesting blog post. What would you say was the most important marketing factor?
October 21st, 2009 at 2:09 am
Hi
Thank you man
You Solve my Problem
God Bless
ali’s last blog post: تشیع علوی و تشیع صفوی