Solved

about SubStr

Posted on 2004-04-08
12
976 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
[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
12 Comments
 
LVL 9

Expert Comment

by:auke_t
ID: 10789863
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
ID: 10789876
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
ID: 10789888
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
Independent Software Vendors: 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 6

Expert Comment

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

Expert Comment

by:mokule
ID: 10790965
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
ID: 10791083
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
 
LVL 17

Expert Comment

by:mokule
ID: 10791117
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
ID: 10791227
What?
0
 
LVL 17

Expert Comment

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

Expert Comment

by:rbohac
ID: 10791507
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
ID: 10791555
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
ID: 10796340
Maybe that code is using madStrings (which is freeware)?

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

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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