Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I need help on this!

porodoroporodoro Posts: 230Member

I've got a string with the following text:

"Username:test !"

How can i remove "Username and the "!" ??

Comments

  • zibadianzibadian Posts: 6,349Member
    :
    : I've got a string with the following text:
    :
    : "Username:test !"
    :
    : How can i remove "Username and the "!" ??
    :
    To delete the !, you can use the Delete() function in combination with the length() function.
    You can delete the username with Delete() and Pos() to find the location of the colon (:).
  • porodoroporodoro Posts: 230Member
    : :
    : : I've got a string with the following text:
    : :
    : : "Username:test !"
    : :
    : : How can i remove "Username and the "!" ??
    : :
    : To delete the !, you can use the Delete() function in combination with the length() function.
    : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    :
    Thanks zibadian , i'll give a try!

  • porodoroporodoro Posts: 230Member
    : : :
    : : : I've got a string with the following text:
    : : :
    : : : "Username:test !"
    : : :
    : : : How can i remove "Username and the "!" ??
    : : :
    : : To delete the !, you can use the Delete() function in combination with the length() function.
    : : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    : :
    : Thanks zibadian , i'll give a try!
    :
    :
    Okay , i wrote this:
    q:=edit1.Text;
    a:=pos(':',q);
    i:=-1;
    while (i <= a) do begin
    i:=i+1;
    delete(q,i,1);
    end;
    delete(q,pos(':',q),1);
    Delete(q,length(edit1.Text),1);
    form1.Caption:=q;

    but it doesnt work properly. Why?
  • zibadianzibadian Posts: 6,349Member
    : : : :
    : : : : I've got a string with the following text:
    : : : :
    : : : : "Username:test !"
    : : : :
    : : : : How can i remove "Username and the "!" ??
    : : : :
    : : : To delete the !, you can use the Delete() function in combination with the length() function.
    : : : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    : : :
    : : Thanks zibadian , i'll give a try!
    : :
    : :
    : Okay , i wrote this:
    : q:=edit1.Text;
    : a:=pos(':',q);
    : i:=-1;
    : while (i <= a) do begin
    : i:=i+1;
    : delete(q,i,1);
    : end;
    : delete(q,pos(':',q),1);
    : Delete(q,length(edit1.Text),1);
    : form1.Caption:=q;
    :
    : but it doesnt work properly. Why?
    :
    First of, you don't need to loop through each letter. It is faster to code it like this:
    [code]
    Delete(q, 1, Pos(':', q));
    // Second parameter is the number of letters to delete.
    [/code]
    Secondly after the first Delete() call, the length of q and Edit1.Text differ. Thus the next Delete() call tries to remove a non-existing letter. You should take the length of the string q.
  • porodoroporodoro Posts: 230Member
    : : : : :
    : : : : : I've got a string with the following text:
    : : : : :
    : : : : : "Username:test !"
    : : : : :
    : : : : : How can i remove "Username and the "!" ??
    : : : : :
    : : : : To delete the !, you can use the Delete() function in combination with the length() function.
    : : : : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    : : : :
    : : : Thanks zibadian , i'll give a try!
    : : :
    : : :
    : : Okay , i wrote this:
    : : q:=edit1.Text;
    : : a:=pos(':',q);
    : : i:=-1;
    : : while (i <= a) do begin
    : : i:=i+1;
    : : delete(q,i,1);
    : : end;
    : : delete(q,pos(':',q),1);
    : : Delete(q,length(edit1.Text),1);
    : : form1.Caption:=q;
    : :
    : : but it doesnt work properly. Why?
    : :
    : First of, you don't need to loop through each letter. It is faster to code it like this:
    : [code]
    : Delete(q, 1, Pos(':', q));
    : // Second parameter is the number of letters to delete.
    : [/code]
    : Secondly after the first Delete() call, the length of q and Edit1.Text differ. Thus the next Delete() call tries to remove a non-existing letter. You should take the length of the string q.
    :
    It works great thx!.
    But if i write something like this :
    SetUserAccess("1");
    it doesnt copy the "1",it just delete's everything..
  • zibadianzibadian Posts: 6,349Member
    : : : : : :
    : : : : : : I've got a string with the following text:
    : : : : : :
    : : : : : : "Username:test !"
    : : : : : :
    : : : : : : How can i remove "Username and the "!" ??
    : : : : : :
    : : : : : To delete the !, you can use the Delete() function in combination with the length() function.
    : : : : : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    : : : : :
    : : : : Thanks zibadian , i'll give a try!
    : : : :
    : : : :
    : : : Okay , i wrote this:
    : : : q:=edit1.Text;
    : : : a:=pos(':',q);
    : : : i:=-1;
    : : : while (i <= a) do begin
    : : : i:=i+1;
    : : : delete(q,i,1);
    : : : end;
    : : : delete(q,pos(':',q),1);
    : : : Delete(q,length(edit1.Text),1);
    : : : form1.Caption:=q;
    : : :
    : : : but it doesnt work properly. Why?
    : : :
    : : First of, you don't need to loop through each letter. It is faster to code it like this:
    : : [code]
    : : Delete(q, 1, Pos(':', q));
    : : // Second parameter is the number of letters to delete.
    : : [/code]
    : : Secondly after the first Delete() call, the length of q and Edit1.Text differ. Thus the next Delete() call tries to remove a non-existing letter. You should take the length of the string q.
    : :
    : It works great thx!.
    : But if i write something like this :
    : SetUserAccess("1");
    : it doesnt copy the "1",it just delete's everything..
    :
    That's only logical, since the second Delete() call deletes the last character, which is in this case the first and only character.
  • porodoroporodoro Posts: 230Member
    : : : : : : :
    : : : : : : : I've got a string with the following text:
    : : : : : : :
    : : : : : : : "Username:test !"
    : : : : : : :
    : : : : : : : How can i remove "Username and the "!" ??
    : : : : : : :
    : : : : : : To delete the !, you can use the Delete() function in combination with the length() function.
    : : : : : : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    : : : : : :
    : : : : : Thanks zibadian , i'll give a try!
    : : : : :
    : : : : :
    : : : : Okay , i wrote this:
    : : : : q:=edit1.Text;
    : : : : a:=pos(':',q);
    : : : : i:=-1;
    : : : : while (i <= a) do begin
    : : : : i:=i+1;
    : : : : delete(q,i,1);
    : : : : end;
    : : : : delete(q,pos(':',q),1);
    : : : : Delete(q,length(edit1.Text),1);
    : : : : form1.Caption:=q;
    : : : :
    : : : : but it doesnt work properly. Why?
    : : : :
    : : : First of, you don't need to loop through each letter. It is faster to code it like this:
    : : : [code]
    : : : Delete(q, 1, Pos(':', q));
    : : : // Second parameter is the number of letters to delete.
    : : : [/code]
    : : : Secondly after the first Delete() call, the length of q and Edit1.Text differ. Thus the next Delete() call tries to remove a non-existing letter. You should take the length of the string q.
    : : :
    : : It works great thx!.
    : : But if i write something like this :
    : : SetUserAccess("1");
    : : it doesnt copy the "1",it just delete's everything..
    : :
    : That's only logical, since the second Delete() call deletes the last character, which is in this case the first and only character.
    :
    So , there isnt any code to prevent deleteting 1 ?
  • zibadianzibadian Posts: 6,349Member
    : : : : : : : :
    : : : : : : : : I've got a string with the following text:
    : : : : : : : :
    : : : : : : : : "Username:test !"
    : : : : : : : :
    : : : : : : : : How can i remove "Username and the "!" ??
    : : : : : : : :
    : : : : : : : To delete the !, you can use the Delete() function in combination with the length() function.
    : : : : : : : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    : : : : : : :
    : : : : : : Thanks zibadian , i'll give a try!
    : : : : : :
    : : : : : :
    : : : : : Okay , i wrote this:
    : : : : : q:=edit1.Text;
    : : : : : a:=pos(':',q);
    : : : : : i:=-1;
    : : : : : while (i <= a) do begin
    : : : : : i:=i+1;
    : : : : : delete(q,i,1);
    : : : : : end;
    : : : : : delete(q,pos(':',q),1);
    : : : : : Delete(q,length(edit1.Text),1);
    : : : : : form1.Caption:=q;
    : : : : :
    : : : : : but it doesnt work properly. Why?
    : : : : :
    : : : : First of, you don't need to loop through each letter. It is faster to code it like this:
    : : : : [code]
    : : : : Delete(q, 1, Pos(':', q));
    : : : : // Second parameter is the number of letters to delete.
    : : : : [/code]
    : : : : Secondly after the first Delete() call, the length of q and Edit1.Text differ. Thus the next Delete() call tries to remove a non-existing letter. You should take the length of the string q.
    : : : :
    : : : It works great thx!.
    : : : But if i write something like this :
    : : : SetUserAccess("1");
    : : : it doesnt copy the "1",it just delete's everything..
    : : :
    : : That's only logical, since the second Delete() call deletes the last character, which is in this case the first and only character.
    : :
    : So , there isnt any code to prevent deleteting 1 ?
    :
    You can check if the last character is an exclamation mark (!) before deleting it. That will stop any other character at the last position from being deleted.
  • porodoroporodoro Posts: 230Member
    : : : : : : : : :
    : : : : : : : : : I've got a string with the following text:
    : : : : : : : : :
    : : : : : : : : : "Username:test !"
    : : : : : : : : :
    : : : : : : : : : How can i remove "Username and the "!" ??
    : : : : : : : : :
    : : : : : : : : To delete the !, you can use the Delete() function in combination with the length() function.
    : : : : : : : : You can delete the username with Delete() and Pos() to find the location of the colon (:).
    : : : : : : : :
    : : : : : : : Thanks zibadian , i'll give a try!
    : : : : : : :
    : : : : : : :
    : : : : : : Okay , i wrote this:
    : : : : : : q:=edit1.Text;
    : : : : : : a:=pos(':',q);
    : : : : : : i:=-1;
    : : : : : : while (i <= a) do begin
    : : : : : : i:=i+1;
    : : : : : : delete(q,i,1);
    : : : : : : end;
    : : : : : : delete(q,pos(':',q),1);
    : : : : : : Delete(q,length(edit1.Text),1);
    : : : : : : form1.Caption:=q;
    : : : : : :
    : : : : : : but it doesnt work properly. Why?
    : : : : : :
    : : : : : First of, you don't need to loop through each letter. It is faster to code it like this:
    : : : : : [code]
    : : : : : Delete(q, 1, Pos(':', q));
    : : : : : // Second parameter is the number of letters to delete.
    : : : : : [/code]
    : : : : : Secondly after the first Delete() call, the length of q and Edit1.Text differ. Thus the next Delete() call tries to remove a non-existing letter. You should take the length of the string q.
    : : : : :
    : : : : It works great thx!.
    : : : : But if i write something like this :
    : : : : SetUserAccess("1");
    : : : : it doesnt copy the "1",it just delete's everything..
    : : : :
    : : : That's only logical, since the second Delete() call deletes the last character, which is in this case the first and only character.
    : : :
    : : So , there isnt any code to prevent deleteting 1 ?
    : :
    : You can check if the last character is an exclamation mark (!) before deleting it. That will stop any other character at the last position from being deleted.
    :
    I found it :) , thanks Zibadian/

Sign In or Register to comment.