Solved

VB functions in delphi

Posted on 2006-11-06
6
285 Views
Last Modified: 2010-04-05
Hi EE

I was wondering if there was a left, mid, right and split functions in delphi? Also I want to remove/replace any ' characters in a string is this possible?

Thanks in advance

Paul
0
Comment
Question by:Paulstott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 17881067
You can use Copy() to get left, right and mid characters and StringReplace() to replace and Delete() to remove.

ziolko.
0
 
LVL 1

Author Comment

by:Paulstott
ID: 17881146
Hi Ziolko,

Thanks for your answer

Would you use the pos function with the copy()? Do you have any example of this?

With string replace I have tried:

StringReplace(aString, ' ' ', ' ', [rfReplaceAll, rfIgnoreCase]); and get an error message, how can I get rid of ' (apostrophe).

Is there a split function or a way to get round this?
0
 
LVL 21

Accepted Solution

by:
ziolko earned 250 total points
ID: 17881246
1. use: StringReplace(aString, '''', '', [rfReplaceAll, rfIgnoreCase]);
(You have to double each: >>'<< within string)

2. yup You can use Pos() with Copy()
var s: string;
     hello, world: string;
     delim: Integer;

s := 'Helo Wrold';
delim := Pos(' ', s);
hello := Copy(s, 1, delim - 1);
world := Copy(s, delim + 1, MaxInt);

ziolko.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17881255
probably need to double up the '

StringReplace(aString, ' '' ', ' ', [rfReplaceAll, rfIgnoreCase]);
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17881279
Here is another split string function I have been using.
Passes back the first string up to the delimiter while also trimming the original string.

function SplitStr(Var AString : String; ADelim : String) : String;
var APos : Integer;
begin
  Result := '';
  APos := Pos(ADelim,AString);
  if APos > 0 then
  begin
    Result := Copy(AString,1,APos-1);
    AString := copy(Astring,APos+length(Adelim),MaxLongInt);
  end
  else
  begin
    Result := AString;
    AString := '';
  end;
end;
0
 
LVL 1

Author Comment

by:Paulstott
ID: 17881280
Thanks for your help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question