Need help in turbo pascal

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
1

Answer Wiki

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

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    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.  
    132,840 pointsBadges:
    report
  • Subhendu Sen
    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
    139,010 pointsBadges:
    report
  • victorbra2u
    I really don't know what to do
     And yes , this is an assignment
    60 pointsBadges:
    report
  • ToddN2000
    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'
    add 1 to counter

    end program
    132,840 pointsBadges:
    report
  • victorbra2u
    Thanks , i will try, not sure if that will work
    60 pointsBadges:
    report
  • ToddN2000
    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.


    132,840 pointsBadges:
    report
  • victorbra2u

    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)"

    60 pointsBadges:
    report
  • ToddN2000
    @victorbra2u: It's been about 30 years since I coded any Pascal. That is about as close as I can remember...Maybe it will point you in the right direction...You might need to move your string to an array and I forget how were set up...
    132,840 pointsBadges:
    report
  • victorbra2u
    That's it 
     We are now studying array
    60 pointsBadges:
    report
  • victorbra2u
    Anyway, thank you 
    60 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: