Need help in turbo pascal

60 pts.
Tags:
Pascal
text replacement
I need a program that can replace every "a" in a word with"b". Does anyone know how I can do this? Thank you.

Software/Hardware used:
Turbo Pascal

Thanks. We'll let you know when a new response is added.

If you want an example with a good detailed explanation check out this answer in this LINK.

Discuss This Question: 10 Replies

Thanks. We'll let you know when a new response is added.
• Sounds like a class assignment as there are numerous examples on the web. Post the code you have tried and what results or errors you get are. We will help you straighten it out so you will understand it better.
report
• Probably this is a homework. Better get ideas to write a program like this. To replace a string, one way you can try to use Pos() function for this. If Pos() finds the value (string), it will return a positive integer, otherwise 0. This is an idea, you can write the actual code based on this. Here is a good tutorial for your knowledge, https://www.tutorialspoint.com/pascal/index.htm
report
• I really don't know what to do
And yes , this is an assignment
report
• If you know the commands but cant figure out the logic, it would go something like this.

Define the variable (string to do the replace with)
get length of variable (to determine the loop count)
initialize a counter  x
start loop at counter x until x = length
get position x of string
test if position x = 'a'
if true the replace with 'b'

end program
report
• Thanks , i will try, not sure if that will work
report
• It's been a long time but maybe something like this.
Correct me if I'm wrong

```begin
var S : String[20];
S := 'My String Value';
for i:=1 to 20 do
begin
if s(i) = 'a' then
s(i) = 'b'
end
end;
end.```

report
• program hdje;
var S : String[20];
i : Integer;
begin

S := 'My String Value';
for i:=1 to 20 do begin
if s(i) = 'a' then s(i) = 'b'
end
end;
end.

Cannot resolve function or procedure "s(^Integer)"