Have a bit of a weird one and hopefully someone can help out.
The company I work for is doing an ad and we are looking for a Pascal programmer and we thought we'd incorporate some Pascal code into the ad itself. The only problem is we do not have any knowledge regarding Pascal. So after a little research the code we have come up with is:
Begin
Write('Enter in Name:');
readln(company);
Write('Enter in Australia:');
readln(country);
writeln;{new line}
writeln;{new line}
Writeln('Programming specialists:', 'company' ,'country');
Readln;
End.
And what we are trying to say is:
The person types in Name
And then types in Australia
And then on the screen appears Programming specialists: Name Australia
So is the syntax correct are we missing anything? like comma's or semi-colons etc
It seems fine except for this line:
Writeln('Programming specialists:', 'company' ,'country');
You're printing the strings "company" and "country", but I assume you actually want the values entered by the user. So it should be:
Writeln('Programming specialists:', company ,country);
That seems fine to me. I'm pretty fresh for programming in Pascal - did it in my college course only a couple of months ago. Take into account casablanca's comment though.
Also, make sure you have the top half of the program correct. Like so:
Program advert; {or any other pertinent name}
Uses crt; {This may be unneeded, but we were taught to always put it in}
Var
company, country: string;
Begin
Writeln('Enter in name');
{Writeln or write depends on how you want this to work - write will make the input on the same line (in a terminal) and writeln will make the input on line below}
Readln(company);
Write('Enter in Australia');
Readln(country);
Writeln;
Writeln;
Writeln('Programming specialists: ', company, ' ', country);
Readln;
End.
In regards to the Readln at the end of the program, you might not need to use it. This essentially 'pauses' the program until the user presses the enter key. I noticed that in Windows the command prompt had a habit of closing at the end, making a final readln necessary, but in a Linux terminal, running the program from the terminal, this doesn't happen. Just a side note for you to consider.
You could test this yourself with Free Pascal.
you must remove the ' (single cuotes) character from the company and country variables, try this
var
company,country :string;
Begin
Write('Enter in Name:');
readln(company);
Write('Enter in Australia:');
readln(country);
writeln;{new line}
writeln;{new line}
Writeln('Programming specialists:', company,' ' ,country);
Readln;
End.
you can check this free ebook to learn more about the pascal syntax
Marco Cantù's Essential Pascal
Related
I have been developing a proof of concept of free text analytics. The RUTA scripts which I have developed for account number, date, salutations, addresses, pin codes, name seem to work properly.
But I am stuck on one rule where I want to extract the license number in UK format from a textual paragraph. The rule I developed seems to work properly when it is alone passed as input but for some reason it fails in a text.
Any help would be highly appreciated as I have been with this issue for quite sometime.
PACKAGE uima.ruta.example;
DECLARE VarA;
DECLARE VarB;
DECLARE VarC;
W{REGEXP("^(?i)(a-z){2}") -> MARK(VarA)}
NUM{REGEXP("..") -> MARK(VarB)}
W{REGEXP("(?i)(a-z){3}$") -> MARK(VarC), MARK(EntityType,1,3), UNMARK(VarA), UNMARK(VarB), UNMARK(VarC)};
The format which I am expecting is
C - Character
N - Number
CCNNCCC
CCNN CCC
Your question(or problem) is not totally clear for me. Also the example script doesn't work (EntityType is not declared and the regular expressions are not valid).
I made an example script. Maybe that will help you:
create or replace procedure HelloWorld(s varchar)
as
begin
dbms_output.put_line(s);
end;
-------- click execute button now
exec HelloWorld('Hello');
The codes above is from the school slide. The first code is shown as 'procedure created' which means good to go. When I execute it by using 'exec HelloWorld(‘Hello’);', it shows errors. May I ask some of question regarding this code please?
1) Why it does not work when I execute it?
2) I know that 's' is a parameter, and 'varchar' is the datatype for 's'. However, the code requires that print 's'. As I can see, there is nothing to assigned on 's'. Then, how can the code runs the value of 's' in 'dbms_output.put_line(s);'?
3)Can anybody just explain what is the basic function for each single word?
I was trying to make a little test program to count how many times letter 'a' appears in an text without using string type:
program PascalTest;
uses WinCrt;
var
a:integer;
ch:char;
begin
a:=0;
writeln('Input text: ');
read(ch);
while ch <>'.' do // '.' marking the end of text ("eoln" could've been used instead)//
begin
case ch of
'A','a':a:=a+1;
end;
read(ch);
end;
writeln(a);
readln;
readln; //forcing output window to stay open//
end.
I noticed that if I dont add another 'readln' statement at the end , the output window will not show results (it will flash in an instant if u will).This is happening only with this program.All the other ones require only one 'readln' so the window can stay open. Can somebody explain to me why is another 'readln' statement needed in this case?
The first readln ends the while loop. Note that you can enter many '.' without loop exit. Further note the writeln(a) is delayed until you press <Enter>. The second readln allows you to view the output.
Make a test: Uncomment both readln and see if you can end the program by entering a '.'.
WinCrt is a consoleless CRT to use in combination with unit GRAPH.
Use unit Crt for normal console output.
I am much of a new bee to Pascal programming I have spent the entire day trying to convert a string to a valid date that I can later use to subtract another date from to discover the number of days between the two dates. Can you pls pls help me.
I started with this code to try to convert the first date entered in string format to a date that can be used in a calulation:
program TryDate;
Var
date1: TDateTime;
thedate:string;
Begin
Writeln ('Enter date');
Readln (thedate);
date1:=StrToDate (thedate);
Writeln ('The date is ',date1);
end.
The program's basic structure can be seen here:
Begin
Writeln ('Enter customer last name');
readln (clname);
Writeln ('Enter customer first name');
readln (cfname);
Writeln ('Enter Dvd Title');
readln (dvdtit);
Writeln ('Enter Due Date');
readln (dued);
Writeln ('Enter Actual Date Returned');
readln (adret);
daysover:=adret-dued;
readln;
end.
I am expected to expand the program further but was trying to get this small part to work before trying the other components.
Simple instructions and examples or possible solutions will be greatly appreciated.
You haven't specified what the issue with the code you've got so far is. The only issue I can see, if your actual code is exactly like what you've posted, is that you haven't specified uses sysutils;, like this:
program TryDate;
uses
sysutils;
Var
date1: TDateTime;
thedate: string;
Begin
Writeln ('Enter date');
Readln (thedate);
date1 := StrToDate (thedate);
Writeln ('The date is ',date1);
end.
The StrToDate function is part of the sysutils unit, which you need to include in your program through uses to be able to use its procedures, functions, types etc.
In addition to Andriy, you also don't supply OS information, or what format you enter the date.
This is important because on *nix you have to add clocale to your USES clause to initialize locale systems which also include prefered dateformat.
For really scary stuff there is the function scandatetime that can parse most custom created dates: http://www.freepascal.org/docs-html/rtl/dateutils/scandatetime.html
I'm trying to extract the text for a document to index it for search. The below mostly works except various words and punctuation run together. When it removes tags, I need to replace them with spaces so I do not get this issue. I have been trying to figure out the most efficient way to do this but I'm coming up empty so far.
doc = Nokogiri::HTML(html)
doc.xpath("//script").remove
doc.xpath("//style").remove
doc.xpath("//a").remove
text = doc.text.gsub(/\s+/,' ')
Here is some sample text I extracted from http://www.washingtontimes.com/blog/redskins-watch/2012/oct/18/redskins-linemen-respond-jason-pierre-paul-rg3-com/
Before the season it was New York Giants defensive end Osi Umenyiora
who made waves by saying he wouldn't call Robert Griffin III by “RG3”
until he did something. Until then, it was “Bob Griffin.”After
Griffin's 76-yard touchdown run in the Washington Redskins' victory
over the Minnesota Vikings, fellow Giants defensive end Jason
Pierre-Paul was the one who had some comments about Griffin.“Don’t
bring it to my side," Pierre-Paul told New York media. “Go the other
way. …“Yes, it'll be a very good matchup. Not on my side, though. Not
on my side. Or the other side.”Griffin, asked jokingly Wednesday about
running for office, said: “I’ve got a lot other guys to be running
away from right now, Pierre-Paul, Osi, all those guys.”But according
to a couple of Redskins linemen, Griffin shouldn't have much to worry
about Sunday if he gets into the open field.“If Robert gets into that
situation, I don't think there's many people that can run him down,”
right guard Chris Chester said. “I'm still going to go out there and
try to block and make sure no one touches Robert at all. But he's a
plenty good athlete to be able to outrun a lot of people in this
league.”Prompted with Pierre-Paul's comments, left tackle Trent
Williams responded: “What do you want me to say about that?”“Robert's
my guy. I don't know Pierre-Paul. I don't know why he would say
something like that,” he said. “Maybe he knows something I don't.”
You could try inserting a space before each p tag:
doc.search('p').each{|el| el.before ' '}
but a better approach probably is something like:
text = doc.search('div.story p').map{|p| p.text}.join(" ")
Other answers are discussing inserting whitespace into the document, but if (as the question asks) your requirement is to replace those nodes with whitespace, Nokogiri has a replace method. So to replace script tags with spaces do:
doc.xpath('//script').each do |node|
node.replace(' ')
end
The question also asks about 'correct' spacing. Most browsers will not insert a space when they render around a <script> tag, so while useful for text extraction, this is not necessarily the 'correct' thing to do.