How Can i Delete blank char in a string???

TnTpureheartTnTpureheart Member Posts: 7
Hi i'm new of the forum and i need your help! i'm trying in all the way to delete the white spaces in a string!!but i can't find a solution!! i have imported datas with a dataport in a table, now i want to remove white spaces in the field "VAT Registration No."!!! i used the code below...
what's wrong?
why it doens't work? please help me to find a solution


blanktext := '';
FOR i :=1 TO STRLEN("VAT Registration No.") DO BEGIN
IF "VAT Registration No." <> ' ' THEN
BlankText := BlankText + FORMAT("VAT Registration No.");
END;

"VAT Registration No." := BlankText;

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Try this:
    FOR i := 1 TO STRLEN("VAT Registration No.") DO BEGIN 
      IF COPYSTR("VAT Registration No.",i,1) <> '' THEN
        BlankText := BlankText + COPYSTR("VAT Registration No.",i,1);
    END;
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • TnTpureheartTnTpureheart Member Posts: 7
    It doesn't work... :-(
    how is it possible?
    is it couse the datas come from a dataport?
  • jhoekjhoek Member Posts: 216
    Check out the on-line help for the DELCHR function!
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • TnTpureheartTnTpureheart Member Posts: 7
    ](*,)
    Yes i've already tried even with DELCHR function...
    help help :-(
  • TnTpureheartTnTpureheart Member Posts: 7
    The strange thing is that the white space is not recognized like a space...
    in the txt file i used for importing data some character are like this "ÿ" and then when i import them they become " " so i think that even if they become white spaces, after importing, they are not the character " "...
    Anyone have an idea?
    :(
  • jhoekjhoek Member Posts: 216
    You could use a hex editor to find out the ASCII value of this character. Once you find out, you can use DELCHR to remove that specific character.
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • TnTpureheartTnTpureheart Member Posts: 7
    OK i found the ascii code is FF now the correct sintax is this?

    DELCHR(String,'=',FF);

    thanx thanx thanx
  • ara3nara3n Member Posts: 9,257
    do this
    create a variable myChar of type Char. and another variable for mytext as text

    in your code

    do this

    MyChar := 255; /note 255 is decimal for hex FF
    Mytext := format(MyChar);

    DELCHR(String,'=',Mytext);
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • TnTpureheartTnTpureheart Member Posts: 7
    Oh thanxs a lot to all of u!!!
    now it works!! i have another question...Can i in a dataport for importing data put some code to manipulate all the field for removing a character without putting the code in every dataport fields??
    :?
  • ara3nara3n Member Posts: 9,257
    on beforeimport trigger you can write your code.

    Also use an array to put the data in first. Then write a forloop to go through the array and run your delete chr function. Then assign the array to your record fields.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • krikikriki Member, Moderator Posts: 9,118
    ara3n wrote:
    do this
    create a variable myChar of type Char. and another variable for mytext as text

    in your code

    do this

    MyChar := 255; /note 255 is decimal for hex FF
    Mytext := format(MyChar);

    DELCHR(String,'=',Mytext);
    The 255-char is called hard-space. Sometimes in it usefull to have a blank space in a string that doesn't behave like a normal space.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.