Solved

about SubStr

Posted on 2004-04-08
12
969 Views
Last Modified: 2010-04-05
While reading, I came across a line of codes which I don't understand.
Can somebody explain to me what the below codes are doing?

Trim(SubStr(myText.Strings[i], 2, ';'));
0
Comment
Question by:cybermilky
12 Comments
 
LVL 9

Expert Comment

by:auke_t
Comment Utility
I think it will take the i-th line from the myText and copy the line starting at the second symbol until the first ';'.

So if mytext would be like

ASome;
BText in here; to be copied;
CWill it work;

Then Trim(SubStr(myText.Strings[1], 2, ';'));

would return 'Text in here'

But just guessing here...

You could search the program for the declaration of the SubStr function as I think it's not an official Delphi function.
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
Trim(..) removes leading and trailing spaces and control characters from the given string S.

SubStr must be some function returnig string.

It should be declared and defined in the code.
0
 
LVL 12

Expert Comment

by:esoftbg
Comment Utility
Trim:
Trims leading and trailing spaces and control characters from a string.

SubStr is probably a function that extracts a substring from a string using parameters (type of Integer and Char or string).
You need to find this function to see the way it works....

emil
0
 
LVL 6

Expert Comment

by:rbohac
Comment Utility
SubStr is most likely equvilent to the copy procedure in Delphi
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
Hey guys,
don't be fortune-tellers.
It is not known from the code above what SubStr is doing.
0
 
LVL 6

Expert Comment

by:rbohac
Comment Utility
I wasn't trying for that... just based on the code though the substr function appears as though it is defined as

function SubStr(S:String;StartPos:Integer;EndChar:Char):String;
begin
  Result := Copy(S,StartPos,Pos(EndChar,S) -StartPos);
end;

Based both on the context and how the substr function is defined in other programming languages
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 17

Expert Comment

by:mokule
Comment Utility
So..
what would You tell about
It takes second section from given string delimited by ';'.
And so on and on..
0
 
LVL 6

Expert Comment

by:rbohac
Comment Utility
What?
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
Imagine
str := 'aaaaaaaaaa;bbbbbbbbbbbbbbb;ccccccccccccccc;dddddddddddd'
SubStr(str,2,';')
returns
bbbbbbbbbbbbbbb
How do Uou like it?
0
 
LVL 6

Expert Comment

by:rbohac
Comment Utility
umm.. Thats what startpos is for. Similar to both the copy command and pos. You have to do the programming yourself.

the function obviously uses a startpos of "2". The point of the function is to copy a SubString out of a larger string, not chop up the string.

In your case SubStr(str,12,';') would return bbbbbbbbbbbbbbb

Judging by the vague description posted, he is probably reading values from either a file, or from a network somehow, line by line. I say this because of the Trim statement.

If you wanted to you could extend the SubStr function and pass S as a var paramater like so

function SubStr(var S:String;StartPos:Integer;EndChar:Char;Const RemoveString:Boolean = False):String;
begin
  Result := Copy(S,StartPos,Pos(EndChar,S) -StartPos);
  if RemoveString then
    Result := Copy(Result,1,StartPos-1)+Copy(Result,StartPos + Length(Result),Length(S));
end;

Which would remove the section you return, however you would have to pass the function a string variable instead of just passing it a string.
0
 
LVL 6

Expert Comment

by:rbohac
Comment Utility
My mistake

function SubStr(var S:String;StartPos:Integer;EndChar:Char;Const RemoveString:Boolean = False):String;
begin
 Result := Copy(S,StartPos,Pos(EndChar,S) -StartPos);
 if RemoveString then
   S := Copy(S,1,StartPos-1)+Copy(S,StartPos + Length(Result),Length(S));
end;
0
 
LVL 20

Accepted Solution

by:
Madshi earned 20 total points
Comment Utility
Maybe that code is using madStrings (which is freeware)?

http://help.madshi.net/StringSub.htm
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now