ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Number of characters in a string?(urgent)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Number of characters in a string?(urgent)

    Hi all,

    If a have a string of length 20.
    And if i want to count no.of characters in it?
    which is the easiest approch?

    Thnks,
    Susan.

  • #2
    Re: Number of characters in a string?(urgent)

    Code:
    mystringlength = %len(%trim(myfieldof20));
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Number of characters in a string?(urgent)

      Jamief,

      I too approached in the same way,
      but when my String contains "abc def ghi"(i mean spaces between letters),how can i achieve it??

      Comment


      • #4
        Re: Number of characters in a string?(urgent)

        You don't want to count the spaces as characters?

        If this is the case then do a %xlate to remove the strings and then continue as Jamie suggested...

        I'll double check the %xlate for an example....brb.
        Your future President
        Bryce

        ---------------------------------------------
        http://www.bravobryce.com

        Comment


        • #5
          Re: Number of characters in a string?(urgent)

          I believe this would work...

          Code:
          mystringlength = %len(%trim(%xlate(' ' : '' : myfieldof20)));
          If not, something verrry similar... you could probably use %replace as well.


          P.S. This is untested...
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment


          • #6
            Re: Number of characters in a string?(urgent)

            well ya didnt say ignore the spaces

            Code:
            d fnd             s              3  0                                    
            d string          s             22    inz('Special Care Assistant')      
             *                                                                       
             *                                                                       
             /free                                                                   
                                                                                     
                   dou fnd = %len(string);                                           
                   fnd = %scan(' ' : string:fnd+1);                                  
                   STRING = %replace('' : string:fnd:1);                             
                   enddo;                                                            
                   dsply string ' ' ;                                                
                                                                                     
                  *inlr = *on;                                                       
                                                                                     
             /end-free
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: Number of characters in a string?(urgent)

              Is there a way to move any posts with "urgent" in them to the bottom of the list? just kidding of course!
              Your friends list is empty!

              Comment


              • #8
                Re: Number of characters in a string?(urgent)

                I Know for sure Birgitta has some SQL ?

                = the number of chars in a string without spaces !

                I think you can do it with: LEN and TRANSLATE !
                Last edited by Marc_d; July 10, 2008, 08:40 AM.

                Comment


                • #9
                  Re: Number of characters in a string?(urgent)

                  Originally posted by jamief View Post
                  well ya didnt say ignore the spaces

                  Code:
                  d fnd             s              3  0                                    
                  d string          s             22    inz('Special Care Assistant')      
                   *                                                                       
                   *                                                                       
                   /free                                                                   
                                                                                           
                         dou fnd = %len(string);                                           
                         fnd = %scan(' ' : string:fnd+1);                                  
                         STRING = %replace('' : string:fnd:1);                             
                         enddo;                                                            
                         dsply string ' ' ;                                                
                                                                                           
                        *inlr = *on;                                                       
                                                                                           
                   /end-free




                  This doesnt work.....
                  Is there a way to replace only one character??

                  Comment


                  • #10
                    Re: Number of characters in a string?(urgent)

                    I think Jamie's does the same thing as mine, but here's another snippet ...

                    Your friends list is empty!

                    Comment


                    • #11
                      Re: Number of characters in a string?(urgent)

                      I Know for sure Birgitta has some SQL ?
                      Sure I have

                      PHP Code:
                      Exec SQL  Set :MyLength Length(Trim(Replace(:MyText' '''))); 
                      Birgitta
                      Last edited by B.Hauser; July 14, 2008, 07:23 AM.

                      Comment

                      Working...
                      X