@Formula Snippet – Strip leading zeros from @NoteId

July 27, 2012 – 6:11 am

We use @NoteId in a view to get the NoteId of a document and display the value in a column. Via NotesNavigator, we access this column ( and others ) Unfortunately, the value, that is returned by the formula is something like NT0000903.

When we pass this value to our function, to open the document in a tabContainer, it fails because the function excepts only the number part wthout the NT and leading zeros. ( = 903 ). So I was looking for a way to stip the unwanted part from the string.

Here is, what I came out with

tmp:=@ReplaceSubstring(@NoteID;"NT";"");
@Do(tmp := tmp;@While(@Length(tmp) > 1 & @Begins(tmp; "0");tmp := @Middle(tmp; 1; 8));tmp) ;

If there is a better solution, let me know. We tried many things, but to go thru the value from left to right and checking, if the string begins with a “0″ seems to be the best way to achieve the aim.

  1. 17 Responses to “@Formula Snippet – Strip leading zeros from @NoteId”

  2. Have you tried this one?

    @RightBack(@NoteID;”0″)

    By Sven Hasselbach on Jul 27, 2012

  3. Of course, but when you have a NoteId with NT0001022, it will return 22 instead of 1022

    By Ulrich Krause on Jul 27, 2012

  4. Oh, my fault. But this should work as required:

    @Text(@TextToNumber(@RightBack(“NT0001022″;”NT”)));

    By Sven Hasselbach on Jul 27, 2012

  5. Nope :) because the NoteId can be NT00001AE and a TextToNumber will return 1 and not 1AE

    By Ulrich Krause on Jul 27, 2012

  6. Sorry Sven, that one fails too. A Note ID is hexadecimal.

    By Dragon Cotterill on Jul 27, 2012

  7. What about this?

    @Implode(@Trim(@Explode(@RightBack(“NT00101AE”;”NT”);”0″));”0″)

    By Sven Hasselbach on Jul 27, 2012

  8. Cool, it works

    By Ulrich Krause on Jul 27, 2012

  9. Upps, sorry Sven, when the last number in the ID is 0, then this 0 is also stripped.

    By Ulrich Krause on Jul 27, 2012

  10. Three shots, three missed… I am giving up!

    By Sven Hasselbach on Jul 27, 2012

  11. I just cheat. @ReplaceSubstring(@NoteID; “NT00000″:”NT0000″:”NT000″:”NT00″:”NT0″; “”)

    By Dragon Cotterill on Jul 27, 2012

  12. :) :) Yes, we had this also, but found it not to be … profesional …

    By Ulrich Krause on Jul 27, 2012

  13. Who cares if it’s not professional… so long as it works and processes faster than a while loop. :)

    By Dragon Cotterill on Jul 27, 2012

  14. Similar solution only with @for. In case you have a “high” NoteId, it might be faster I guess :-)

    _Tmp:=@ReplaceSubstring(@NoteID;”NT”;”");
    _Len := @length(_tmp);
    @For(x := 0 ; x =< _len ; x:=x+1;
    @If(@Middle(_tmp;x;1) “0″;
    @Do(
    @Set(“_Tmp”;@Right(_tmp;_len-x));
    x := _Len
    )
    ;”")
    );
    _Tmp

    Since you said you have to use it in a view, you can’t use @return, Otherwise the @do / @set could be replaced with a @return

    By Art Zoutendijk on Aug 3, 2012

  15. hmmm when re-reading just noticed that the @set can be replace with just _tmp := as well :-)

    By Art Zoutendijk on Aug 3, 2012

  16. What do you think about this solution:

    _NoneNT:= @Right (“NT001001AE”; 8);
    _NoneZero:= @Trim(@ReplaceSubstring(_NoneNT; “0″; “”));
    @Left(_NoneZero; 1) + @Right (_NoneNT; @Left(_NoneZero; 1));

    By Andre on Aug 9, 2012

  17. Ups, @Trim is not necessary

    _NoneNT:= @Right (“NT001001AE”; 8);
    _NoneZero:= @ReplaceSubstring(_NoneNT; “0″; “”);
    @Left(_NoneZero; 1) + @Right (_NoneNT; @Left(_NoneZero; 1));

    By Andre on Aug 9, 2012

  18. Cool, Thx Andre

    By Ulrich Krause on Aug 9, 2012

Sorry, comments for this entry are closed at this time.