how to check for blank spaces in asp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meenu_susi
    New Member
    • Jun 2006
    • 47

    how to check for blank spaces in asp

    how to check for blank spaces in asp

    when the user input their name...
    for (ex) sri ram...
    then i want to get the first letters that is "s" and "r" frm the input..
    how to do this..
    i am able to get the first letter "s" but not the second..
    how to do this... in asp
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Hi there,

    well.. looping will be a great solution i guess.. first read the string as whole.. use looping method to capture 1st 2 characters..

    Comment

    • sashi
      Recognized Expert Top Contributor
      • Jun 2006
      • 1749

      #3
      Hi there,

      well.. mid function will also be a great solution i guess.. first read the string as whole.. use looping method to capture 1st 2 characters.. see the example below..

      Code:
      Mid(string,start[,length])
      
      Parameter  	Description
      string 	          - Required. The string expression from which characters are returned
      start 	           - Required. Specifies the starting position. If set to greater than the number of characters in string, it returns an empty string ("")
      length 	          - Optional. The number of characters to return
      Code:
      dim txt
      txt="This is a beautiful day!"
      document.write(Mid(txt,1,2))
      
      Output: Th

      Comment

      • meenu_susi
        New Member
        • Jun 2006
        • 47

        #4
        hello
        thanks for ur reply ...
        i have tried the following

        <%
        for i=1 to len(mytext)

        str1=instr(i,my text," ")

        str3=mid(mytext ,str1+1,1)

        response.write str3

        next
        i=i+1
        %>
        where str1 is fr indentifying the position of blankspace in the name

        i have tried with the above loop
        but i am getting the starting letters in the name..
        for ex
        i input the name as maya sumi
        and i got the result as sssssmmmm

        from this i want to get s and m seperately..
        how to do any idea...

        with regards
        meenu

        Comment

        • ilaiyaraja
          New Member
          • Jul 2006
          • 6

          #5
          THis one may help u

          mytext="maya sumi"

          str1=mid(mytext ,1,1)
          str2=mid(mytext ,(instr(mytext, " "))+1,1)

          response.write( "Your string is: "& mytext)
          response.write( "<br> The first and second first after space as follows.")

          response.write( "<br>"&str1 )
          response.write( str2)

          Regards.....

          raja :)

          Comment

          • danp129
            Recognized Expert Contributor
            • Jul 2006
            • 323

            #6
            Code:
            response.write GetInitials("Adam S. Peterson")
            
            function GetInitials(strin)
              artmp=split(strin, " ")
              for i = 0 to ubound(artmp)
            	'instead of storing in "ret" variable you could do your own thing with the letter
                ret=ret & sep & left(artmp(i),1) 'get first letter of this name
                sep=" " 'if you want a seperator
              next 'i
              GetInitials=ret
            end function

            Comment

            • meenu_susi
              New Member
              • Jun 2006
              • 47

              #7
              hi raja

              if the name is maya sumi
              its working but when i input as maya sumi maya
              then i want the result as m s m
              this has to be done using for loop
              but i dont knw how to do

              can u help me out

              Comment

              • vinodkvee
                New Member
                • Jul 2006
                • 9

                #8
                try

                <%
                mytext = "One two three"
                for i=1 to len(mytext)

                mypos=instr(i,m ytext," ")

                if mypos <> 0 and i = 1 then
                mystr=mid(mytex t,1,1)
                response.write mystr
                elseif mypos <> 0 then
                mystr=mid(mytex t,i+1,1)
                response.write mystr
                end if
                i=i+1
                next
                %>

                Comment

                Working...