Delete space in a string

iqbalmadiqbalmad Member Posts: 179
amttext := FORMAT(amt,0);

--- DELCHR(amttext) ---
i am using this delchr to delete the spaces that is found in my amount.

Before After
389 510 >> 389510

But this is not the case. Can someone tell me y?

Comments

  • jhenavjhenav Member Posts: 6
    NewString := DELCHR(String [, Where] [, Which])


    Try to give the WHERE and WHICH parameter.

    NewString := DELCHR(Amttext, '=', ' ');
  • iqbalmadiqbalmad Member Posts: 179
    that too doesnt work jhenav
  • garakgarak Member Posts: 3,263
    x := '  389 510 456 65';
    y := delchr(x,'=',' '); //NOT '', use SPACE in ''
    

    Regards
    Do you make it right, it works too!
  • iqbalmadiqbalmad Member Posts: 179
    i have tried this too.. still doesnt work..

    ps: my amount is a decimal field.
  • kinekine Member Posts: 12,562
    :-) than you mean that you want to print the number without thousend separator.... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    Stop?! Is the BEFORE variable a decimal or a text? Do you whish only delete the separetors if it is a decimal and in your local settings this separators exist?

    So. what is X (BEFORE) it is text? Sure????.
    What is y (After) text or decimal? You say u need decimal, ok, no problem.
    x := '  389 510 456 65'; //x is text
    evaluate(y,delchr(x,'=',' ')); //y is decimal
    

    Regards
    Do you make it right, it works too!
  • iqbalmadiqbalmad Member Posts: 179
    yes kine.. i am sending my decimal field in a txt file.. and i want to remove the thousand separators.. i no i can change my local settings for that..

    but users have this as their local settings.. and the bank wants the numbers without the <space> separators.
  • garakgarak Member Posts: 3,263
    iqbalmad wrote:
    yes kine.. i am sending my decimal field in a txt file.. and i want to remove the thousand separators.. i no i can change my local settings for that..
    Why do you not say this in the first post ,..... arg

    You format the Amount and delete the BLANKS.
    Combinate both functions like:

    ValueToWriteInTheTextFile := delchr(format(Amount),'=',' ');
    Do you make it right, it works too!
  • iqbalmadiqbalmad Member Posts: 179
    hi garak.

    This is my function

    FormatAmtNMC(AmountToFormat : Decimal;VAR text5 : Text[16])
    len := STRLEN(FORMAT(AmountToFormat,0));


    IF len = 1 THEN text5 := '000000000000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 2 THEN text5 := '00000000000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 3 THEN text5 := '0000000000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 4 THEN text5 := '000000000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 5 THEN text5 := '00000000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 6 THEN text5 := '0000000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 7 THEN text5 := '000000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 8 THEN text5 := '00000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 9 THEN text5 := '0000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 10 THEN text5 := '000000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 11 THEN text5 := '00000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 12 THEN text5 := '0000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 13 THEN text5 := '000' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 14 THEN text5 := '00' + DELCHR(FORMAT(AmountToFormat),'=',' ');
    IF len = 15 THEN text5 := '0' + DELCHR(FORMAT(AmountToFormat),'=',' ');

    Result on screen : 00000002 207 680
    Result on txt file : 00000002ÿ207ÿ680
  • iqbalmadiqbalmad Member Posts: 179
    hi guys,

    i managed to find another similar topic:
    viewtopic.php?f=5&t=36319&hilit=decimal

    since my client does not have decimal places in amounts, i am using

    IF len = 1 THEN text5 := '000000000000000' + FORMAT(AmountToFormat, 0, '<Integer>');

    thanks for the guidance.
  • kinekine Member Posts: 12,562
    What about using while loop to pad the string by 0 from left? Or some function for that? Or fill char in the format? :wink:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • RnRRnR Member Posts: 21
    t_myString := 'some text';
    t_NewString := FORMAT(t_myString,0,STRSUBSTNO('<text,%1><filler character,0>',20))
    t_NewString is now: '00000000000some text'
    STRLEN(t_NewString) = 20

    t_NewString := FORMAT(t_myString,0,STRSUBSTNO('<text,%1><filler character,'.'>',20))
    t_NewString is now: '...........some text'
    STRLEN(t_NewString) = 20

    Another solution:
    Fill trailing
    t_NewString := t_myString + PADSTR('',20 - STRLEN(t_myString),'.');
    t_NewString is now: 'some text...........'

    Fill leading
    t_NewString := PADSTR('',20 - STRLEN(t_myString),' ') + t_myString;
    t_NewString is now: '...........some text'

    * had to use . instead og space since spaces gets trimmed in the forum
Sign In or Register to comment.