?
Solved

about SubStr

Posted on 2004-04-08
12
Medium Priority
?
977 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

743 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