Web Analytics Made Easy -
StatCounter Removing percentages from a string - CodingForum

Announcement

Collapse
No announcement yet.

Removing percentages from a string

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

  • Removing percentages from a string

    Hello all,

    I am receiving a string from a flash application however i need to remove the percentages from the string to process it in my asp script.

    the strings i am getting are like this:

    %AA%AA%AA%AA%AA
    %AA%AA%AA
    %AA

    This one processes fine, but the longer ones won't.
    %AA

    Is there a way i can remove them (even though they won't all be the same size string) after i have requested them from flash?

    Thanks in advance

    Russ

  • #2
    These percentages - do you mean you're getting stuff through with lots of "%20" and stuff in between words? That's an escaped string. Try:

    str = "Hello, World!"
    response.write(str)
    str = escape(str)
    response.write(str)
    str = unescape(str)
    response.write(str)

    If that's not what you're talking about, can you be more explicit in what you want to do? I mean, you can easily remove all the % symbols with replace(str, "%", ""), or use them to form an array with split(str, "%"). Is that what you mean?

    Comment


    • #3
      Sorry i wasn't too clear, i've made a little more progress and found the values that need to be taken out.

      its basically and encrypted value being sent from flash to asp to verify the submittance.

      the flash output strings are like these:

      %aa
      %aa%C2%aa
      %aa%C2%aa%C2%aa

      The problem is the %c2 which comes up after every value when the string is long enough, these need to be taken out. so the second string should be %aa%aa. otherwise the decrypt script doesn't recognise the string.

      Hope this makes a little more sense!

      Thanks

      Russ

      Comment


      • #4
        You could use a Replace function such as Replace(str,"%", " ") to replace the percentage with a space or whatever you would like.

        Otherwise, use split to make it into an array:
        array = Split(str,"%")

        Good luck!
        Matt

        Comment


        • #5
          Would Replace(str,"%C2", " ") work on all the %C2's that appear in the string or would they have to be done seperately?

          Thanks

          Russ

          Comment


          • #6
            It looks like it to me. If you didn't want to replace them with a space, and just take them out, you could do
            Code:
            Replace(str,"%C2","")
            What I normally do for string manipulation though, is just make a test page and play around with different stuff and write it to the page.
            Matt

            Comment


            • #7
              Thaks for all your help so far, i have done a quick test like you said (below) but its not actually changing the original input value at all. any ideas?

              <%

              dim str

              str = request.form("inputScore")

              call Replace(str,"%C2","")

              response.write (str)

              %>

              Thanks

              Russ

              Comment


              • #8
                My mistake, got an error message saying something about a call function needed to be used, so added it to make it work. Changed the code now and it works a treat.

                <%

                dim str

                str = request.form("inputScore")

                str = Replace(str,"%C2","")

                response.write (str)

                %>

                Cheers guys, the helps much appreciated

                Russ

                Comment


                • #9
                  Glad I could help!
                  Matt

                  Comment


                  • #10
                    Sorry to be a pain, but to get the code to work in my asp script i have to use the server.urlencode function to display the result in the browser. to take the %C2's out (otherwise it just bring up crazy encrypted symbols)

                    score = Replace(server.urlencode(score),"%C2"," ")

                    however, this get's rid of the %C2 but adds 25 after each % as shown below:

                    string before replacing
                    %0E%C2%9D

                    string after replacing
                    %250E1%259D

                    Its should just read:

                    %0E%9D

                    Any ideas why its adding these values?

                    Thanks

                    Russ

                    Comment


                    • #11
                      then when you run your replace, replace it with nothing and not a space
                      Code:
                      score = Replace(server.urlencode(score),"%C2","")

                      Comment


                      • #12
                        Thanks for the response mehere, i was just trying to change the wrong part of the variable. but all is sorted now!

                        Thanks

                        Russ

                        Comment


                        • #13
                          Code:
                          Function URLDecode(str) 
                          	str = Replace(str, "+", " ") 
                          	For i = 1 To Len(str) 
                          		sT = Mid(str, i, 1) 
                          		If sT = "%" Then 
                          			If i+2 < Len(str) Then 
                          				sR = sR & _ 
                          					Chr(CLng("&H" & Mid(str, i+1, 2))) 
                          				i = i+2 
                          			End If 
                          		Else 
                          			sR = sR & sT 
                          		End If 
                          	Next 
                          	URLDecode = sR 
                          End Function
                          
                          str = Server.URLEncode("http://codingforum.net/showthread.php?t=97216")
                          Response.Write str & "<br>"
                          Response.Write URLDecode(str)
                          http://www.degs.co.uk
                          http://www.computer-helpforum.com

                          Comment

                          Working...
                          X