Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

about SubStr

Posted on 2004-04-08
12
Medium Priority
?
979 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
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
Technology Partners: 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 80 total points
ID: 10796340
Maybe that code is using madStrings (which is freeware)?

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

926 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