Click to See Complete Forum and Search --> : Stripping out text in ASP
Danbabe
08-04-2004, 11:52 AM
How can I strip out the first characters before the first / symbol of lets say a membership number such 04/25/01/2004/178.56.
Sometimes the first numbers will be 2 characters and sometimes will be upto 4 characters.
Please help guys - this is frustrating now...
Many thanks
Danny
schizo
08-04-2004, 12:05 PM
Here you go. If you want it to not display the leading "/" replace (searchIndex - 1) with just searchIndex.
<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim str, searchIndex
str = "04/25/01/2004/178.56."
Response.Write(str & "<br />")
' Find index of first /
searchIndex = inStr(str, "/")
' Remove the numbers leading up to the first /
str = Right(str, Len(str) - (searchIndex - 1))
' Output the result
Response.Write(str)
%>
Ouputs:
04/25/01/2004/178.56.
/25/01/2004/178.56.
Danbabe
08-04-2004, 02:15 PM
Thank you for your help.
However, I did not want to remove the first set of numbers, I needed them to be stored seperatly
Any ideas on how to save the first set of numbers seperatly?
Thanks again
Danny
schizo
08-04-2004, 02:18 PM
No problem...
<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim str, searchIndex
str = "04/25/01/2004/178.56."
Response.Write(str & "<br />")
' Find index of first /
searchIndex = inStr(str, "/")
' Cuts the leading numbers before the first /
str = Left(str, (searchIndex - 1))
' Output the result
Response.Write(str)
%>
Outputs:
04/25/01/2004/178.56.
04
Danbabe
08-04-2004, 02:30 PM
You are a genius my man.
Can I be cheeky now. Now you have shown me what can be done, this is what I really need
1. The first number(s) before the first / symbol which you have shown me
2. The numbers after the last / symbol is the amount I also need seperatly
3. The remainder is the order date which I also need seperatly
The final result should be:
04
25/01/2004
178.56
Any ideas on this wizardry?
Cheers again
Danny
schizo
08-04-2004, 03:11 PM
<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim startStr, modStr, searchIndex1, searchIndex2
startStr = "05/25/01/2004/178.56."
Response.Write(startStr & "<br />")
' Find index of first /
searchIndex1 = inStr(startStr, "/")
' Cuts the leading numbers before the first /
modStr = Left(startStr, (searchIndex1 - 1))
' Output the first number(s) before the first /
Response.Write(modStr & "<br />")
' Modify the search index to find the last /
searchIndex2 = inStrRev(startStr, "/")
' Get the last set of numbers
modStr = Right(startStr, (Len(startStr) - searchIndex2))
' Output the last set of numbers
Response.Write(modStr & "<br />")
' Get the middle set of numbers
modStr = Mid(startStr, (searchIndex1 + 1), Len(startStr) - searchIndex1 - (Len(startStr) - searchIndex2) - 1)
' Output the middle set of numbers
Response.Write(modStr)
%>
Output:
0504/25/01/2004/178.56.
0504
178.56.
25/01/2004
Danbabe
08-04-2004, 04:14 PM
Youre the man
Thanks very much
Regards
Danny
If you need a free domain name or web hosting, let me know - ok
danny@fastsitesuk.co.uk