Ask a Question related to ASP Database, Design and Development.
-
Learning #1
How to replace first and last "," in a string in asp vbscript?
How can I replace first as well as last "," in a string?
Mystring = ",3,2,5,6,1,65,22,"
I would like
CorrectedString = "3,2,5,6,1,65,22"
I would like to replace commas on each sides with "".
I am new to asp and would be grateful for your help.
Thanks in advance.
Learning Guest
-
"Error Creating Control" and "Cast from String"
I'm creating a custom date control. In appearance, it's just a textbox and a button. It has three custom properties: CalDate, CalDateType and... -
"replace pages" / "rotate pages" orientation issue
in Adobe acrobat you can open a PDF file and "replace pages" (some or all) with pages from another PDF file. it used to be that when I did this,... -
#26292 [Opn->Bgs]: substr returns "0" for any offset on the string "0"
ID: 26292 Updated by: sniper@php.net Reported By: ravacholp at hotmail dot com -Status: Open +Status: ... -
#25763 [NEW]: Why the string "1.10" is equal to the string "1.1"?
From: jparneodo at yahoo dot fr Operating system: RH7.2 PHP version: 4.3.3 PHP Bug Type: Strings related Bug description: ... -
convert visual basic "string" data type to DB2 "blob"
Does anyone know if a visual basic string data type can be converted to DB2 blob datatype? I have all data in XML files and I use Visual Basic to... -
Ken Schaefer #2
Re: How to replace first and last "," in a string in asp vbscript?
InStr()
-and-
InStrRev()
The first can give you the first ",", and the latter will do the same, but
starting from the end of the string. You can get the VBScript documentation
from here:
[url]http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en[/url]
Cheers
Ken
"Learning" <question_asp@yahoo.com> wrote in message
news:99a92f8.0307151244.1beebfb0@posting.google.co m...
: How can I replace first as well as last "," in a string?
:
: Mystring = ",3,2,5,6,1,65,22,"
:
: I would like to replace commas on each sides with "".
: I am new to asp and would be grateful for your help.
: Thanks in advance.
Ken Schaefer Guest
-
Ken Schaefer #3
Re: How to replace first and last "," in a string in asp vbscript?
Please post in one group only. Answered in:
microsoft.public.inetserver.asp.general
Cheers
Ken
"Learning" <question_asp@yahoo.com> wrote in message
news:99a92f8.0307151247.4e876cef@posting.google.co m...
: How can I replace first as well as last "," in a string?
:
: Mystring = ",3,2,5,6,1,65,22,"
:
: I would like
: CorrectedString = "3,2,5,6,1,65,22"
:
: I would like to replace commas on each sides with "".
: I am new to asp and would be grateful for your help.
: Thanks in advance.
Ken Schaefer Guest
-
Ray at #4
Re: How to replace first and last "," in a string in asp vbscript?
Mystring = Mid(MyString, 2, Len(Mystring)-2)
But let me ask, where is this string coming from?
Ray at work
"Learning" <question_asp@yahoo.com> wrote in message
news:99a92f8.0307151244.1beebfb0@posting.google.co m...> How can I replace first as well as last "," in a string?
>
> Mystring = ",3,2,5,6,1,65,22,"
>
> I would like to replace commas on each sides with "".
> I am new to asp and would be grateful for your help.
> Thanks in advance.
Ray at Guest
-
MDW #5
How to replace first and last "," in a string in asp vbscript?
Mystring = Left(Mystring,Len(Mystring) - 1)
Mystring = Mid(Mystring,2)
That should do it.
>-----Original Message-----
>How can I replace first as well as last "," in a string?
>
>Mystring = ",3,2,5,6,1,65,22,"
>
>I would like to replace commas on each sides with "".
>I am new to asp and would be grateful for your help.
>Thanks in advance.
>.
>MDW Guest
-
Michael #6
Re: How to replace first and last "," in a string in asp vbscript?
Ray, I believe it should be
Len(Mystring) - 1
not
Len(Mystring) - 2
"Ray at <%=sLocation%>" <ask@me.forit> wrote in message
news:eS5XvVxSDHA.2276@TK2MSFTNGP10.phx.gbl...> Mystring = Mid(MyString, 2, Len(Mystring)-2)
>
> But let me ask, where is this string coming from?
>
> Ray at work
>
> "Learning" <question_asp@yahoo.com> wrote in message
> news:99a92f8.0307151244.1beebfb0@posting.google.co m...>> > How can I replace first as well as last "," in a string?
> >
> > Mystring = ",3,2,5,6,1,65,22,"
> >
> > I would like to replace commas on each sides with "".
> > I am new to asp and would be grateful for your help.
> > Thanks in advance.
>
Michael Guest
-
wetchman #7
Re: How to replace first and last "," in a string in asp vbscript?
Also:
MyString = Left(MyString,Len(MyString)-1)
MyString = Right(MyString,Len(MyString)-1)
"Learning" <question_asp@yahoo.com> wrote in message
news:99a92f8.0307151244.1beebfb0@posting.google.co m...> How can I replace first as well as last "," in a string?
>
> Mystring = ",3,2,5,6,1,65,22,"
>
> I would like to replace commas on each sides with "".
> I am new to asp and would be grateful for your help.
> Thanks in advance.
wetchman Guest
-
Ken Schaefer #8
Re: How to replace first and last "," in a string in asp vbscript?
All of these suggestions work only if the string is in the exact specified
format.
If the original poster wishes to find the first comma, and the last comma,
and the string is in some arbitrary format, then you need InStr() and
InStrRev()
Cheers
Ken
"wetchman" <wetchman@NOSPAMhotmail.com> wrote in message
news:gI%Qa.19628$J%2.1900465@news.alltel.net...
: Also:
:
: MyString = Left(MyString,Len(MyString)-1)
: MyString = Right(MyString,Len(MyString)-1)
:
:
: "Learning" <question_asp@yahoo.com> wrote in message
: news:99a92f8.0307151244.1beebfb0@posting.google.co m...
: > How can I replace first as well as last "," in a string?
: >
: > Mystring = ",3,2,5,6,1,65,22,"
: >
: > I would like to replace commas on each sides with "".
: > I am new to asp and would be grateful for your help.
: > Thanks in advance.
:
:
Ken Schaefer Guest
-
Ray at #9
Re: How to replace first and last "," in a string in asp vbscript?
He wanted to get rid of the first and last comma though. So,
,a,b,c,d,e,f, is 13 characters long. If you Mid(), starting at the second
character, you want 11 characters, which is 13-2. Just like if it's ",e,"
he'd only want the e, which is 1 character which is len(",e,")-2.
Ray at home
"Michael" <a@b.c> wrote in message
news:e6KazoxSDHA.1552@TK2MSFTNGP10.phx.gbl...> Ray, I believe it should be
> Len(Mystring) - 1
> not
> Len(Mystring) - 2
>
>
> "Ray at <%=sLocation%>" <ask@me.forit> wrote in message
> news:eS5XvVxSDHA.2276@TK2MSFTNGP10.phx.gbl...>> > Mystring = Mid(MyString, 2, Len(Mystring)-2)
> >
> > But let me ask, where is this string coming from?
> >
> > Ray at work
> >
> > "Learning" <question_asp@yahoo.com> wrote in message
> > news:99a92f8.0307151244.1beebfb0@posting.google.co m...> >> > > How can I replace first as well as last "," in a string?
> > >
> > > Mystring = ",3,2,5,6,1,65,22,"
> > >
> > > I would like to replace commas on each sides with "".
> > > I am new to asp and would be grateful for your help.
> > > Thanks in advance.
> >
>
Ray at Guest
-
Michael #10
Re: How to replace first and last "," in a string in asp vbscript?
You're right. Mystring on the RHS still refers to the original Mystring.
Somehow my brain went ahead, and I already subtracted one character from
Mystring. Thanks.
"Ray at <%=sLocation%>" <ray@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:%236GSikzSDHA.1688@TK2MSFTNGP11.phx.gbl...> He wanted to get rid of the first and last comma though. So,
>
> ,a,b,c,d,e,f, is 13 characters long. If you Mid(), starting at the second
> character, you want 11 characters, which is 13-2. Just like if it's ",e,"
> he'd only want the e, which is 1 character which is len(",e,")-2.
>
> Ray at home
>
>
> "Michael" <a@b.c> wrote in message
> news:e6KazoxSDHA.1552@TK2MSFTNGP10.phx.gbl...>> > Ray, I believe it should be
> > Len(Mystring) - 1
> > not
> > Len(Mystring) - 2
> >
> >
> > "Ray at <%=sLocation%>" <ask@me.forit> wrote in message
> > news:eS5XvVxSDHA.2276@TK2MSFTNGP10.phx.gbl...> >> > > Mystring = Mid(MyString, 2, Len(Mystring)-2)
> > >
> > > But let me ask, where is this string coming from?
> > >
> > > Ray at work
> > >
> > > "Learning" <question_asp@yahoo.com> wrote in message
> > > news:99a92f8.0307151244.1beebfb0@posting.google.co m...
> > > > How can I replace first as well as last "," in a string?
> > > >
> > > > Mystring = ",3,2,5,6,1,65,22,"
> > > >
> > > > I would like to replace commas on each sides with "".
> > > > I am new to asp and would be grateful for your help.
> > > > Thanks in advance.
> > >
> > >
> >
>
Michael Guest
-
Learning #11
Re: How to replace first and last "," in a string in asp vbscript?
Thanks for all your posts.
Sorry I couldn't explain properly, Actually the string is coming from
a loop so it can be lengthy or short. After reading your posts I think
I need InStr()and InStrRev() functions.
I know I can use this function to get the position of the first
occurrence but what after that?
Mystring = ",3,2,5,6,1,65,22,"
Instr(MyString, ",") 'returns 1 for position 1
I am new to asp and would really apreciate help from you guys.
Thanks for all your help so far.
Learning Guest
-
Ray at #12
Re: How to replace first and last "," in a string in asp vbscript?
Show the code for your loop. I'm 99% sure that we can drop the loop
altogether and just give you a comma delimited string all in one swoop
without needing to loop.
Ray at work
"Learning" <question_asp@yahoo.com> wrote in message
news:99a92f8.0307161006.630063fa@posting.google.co m...> Thanks for all your posts.
> Sorry I couldn't explain properly, Actually the string is coming from
> a loop so it can be lengthy or short. After reading your posts I think
> I need InStr()and InStrRev() functions.
>
> I know I can use this function to get the position of the first
> occurrence but what after that?
>
> Mystring = ",3,2,5,6,1,65,22,"
> Instr(MyString, ",") 'returns 1 for position 1
>
> I am new to asp and would really apreciate help from you guys.
> Thanks for all your help so far.
Ray at Guest
-
Ken Schaefer #13
Re: How to replace first and last "," in a string in asp vbscript?
Please go and download the documentation that I provided, and you will have
the answer. InStr() has extra parameters that let you decide where to start
the search.
Cheers
Ken
"Learning" <question_asp@yahoo.com> wrote in message
news:99a92f8.0307161006.630063fa@posting.google.co m...
: Thanks for all your posts.
: Sorry I couldn't explain properly, Actually the string is coming from
: a loop so it can be lengthy or short. After reading your posts I think
: I need InStr()and InStrRev() functions.
:
: I know I can use this function to get the position of the first
: occurrence but what after that?
:
: Mystring = ",3,2,5,6,1,65,22,"
: Instr(MyString, ",") 'returns 1 for position 1
:
: I am new to asp and would really apreciate help from you guys.
: Thanks for all your help so far.
Ken Schaefer Guest
-
Learning #14
Re: How to replace first and last "," in a string in asp vbscript?
I have downloaded the vb documents. Now I know that I can use Instrv()
and InstrvRev() to get the positions.
MyString = ",1,2,3,4,5,6,7,8,"
MyString = Instr(MyString, ",") ' Position 1
MyString = InstrRev(MyString, ",") ' Position 17
But after getting the positions how do I remove the "," ?
Do I need another function to remove them?
I am confused.
That would be great if you can help.
Here is the code.
'----------------------------------------------------------
Dim rsNews
Dim N_IDs
Dim strN_ID
Dim CountN_ID
Dim Count1N_ID
Dim NewRndMax
Dim NewRndNumber
Set rsNews = Server.CreateObject("ADODB.Recordset")
rsNews.ActiveConnection = MM_kdata_STRING
rsNews.Source = "SELECT * FROM News"
rsNews.CursorType = 1
rsNews.CursorLocation = 2
rsNews.LockType = 3
rsNews.Open()
rsNews.MoveLast
CountN_ID = rsNews.RecordCount
Count1N_ID = CountN_ID
NewRndMax = CountN_ID
If 2 < CountN_ID Then
Count1N_ID = 2
End If
N_IDs = ","
strN_ID = ","
Do Until Count1N_ID = 0
Randomize
NewRndNumber = Int(Rnd * NewRndMax)
If (InStr(1, strN_ID, "," & NewRndNumber & "," ) = 0) Then
strN_ID = strN_ID & NewRndNumber & ","
Count1N_ID = Count1N_ID - 1
rsNews.MoveFirst
rsNews.Move NewRndNumber
N_IDs = N_IDs & rsNews("N_ID") & ","
End If
Loop
rsNews.Close
Set rsNews = Nothing
'-----------------------------------------------------------
Learning Guest
-
Ken Schaefer #15
Re: How to replace first and last "," in a string in asp vbscript?
You can use the Replace function to replace something with a zero length
string, or, in your case I'd use Left() and Right()
That said, the code you have is pretty nasty. Are you just trying to find
"x" random records from the database? If so, perhaps the following might
work (not gaurenteed)
<%
strSQL = _
"SELECT TOP 5 News_ID FROM News ORDER BY Rnd(-(1000*ID)*Now())"
Set objRS = objConn.Execute strSQL
If not objRS.EOF then
arrResults = objRS.GetRows
End If
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
Cheers
Ken
"Learning" <question_asp@yahoo.com> wrote in message
news:99a92f8.0307171043.baa312b@posting.google.com ...
: I have downloaded the vb documents. Now I know that I can use Instrv()
: and InstrvRev() to get the positions.
:
: MyString = ",1,2,3,4,5,6,7,8,"
: MyString = Instr(MyString, ",") ' Position 1
: MyString = InstrRev(MyString, ",") ' Position 17
:
: But after getting the positions how do I remove the "," ?
: Do I need another function to remove them?
: I am confused.
: That would be great if you can help.
:
: Here is the code.
: '----------------------------------------------------------
: Dim rsNews
: Dim N_IDs
: Dim strN_ID
: Dim CountN_ID
: Dim Count1N_ID
: Dim NewRndMax
: Dim NewRndNumber
:
: Set rsNews = Server.CreateObject("ADODB.Recordset")
: rsNews.ActiveConnection = MM_kdata_STRING
: rsNews.Source = "SELECT * FROM News"
: rsNews.CursorType = 1
: rsNews.CursorLocation = 2
: rsNews.LockType = 3
: rsNews.Open()
:
: rsNews.MoveLast
: CountN_ID = rsNews.RecordCount
: Count1N_ID = CountN_ID
: NewRndMax = CountN_ID
:
: If 2 < CountN_ID Then
: Count1N_ID = 2
: End If
:
: N_IDs = ","
: strN_ID = ","
:
: Do Until Count1N_ID = 0
: Randomize
: NewRndNumber = Int(Rnd * NewRndMax)
:
: If (InStr(1, strN_ID, "," & NewRndNumber & "," ) = 0) Then
: strN_ID = strN_ID & NewRndNumber & ","
: Count1N_ID = Count1N_ID - 1
: rsNews.MoveFirst
: rsNews.Move NewRndNumber
: N_IDs = N_IDs & rsNews("N_ID") & ","
: End If
: Loop
: rsNews.Close
: Set rsNews = Nothing
: '-----------------------------------------------------------
Ken Schaefer Guest
-
Learning #16
Re: How to replace first and last "," in a string in asp vbscript?
I tried:
MyString = ",1,2,3,4,5,6,7,8,"
MyString = mid(MyString,2,len(MyString)-2)
and it works fine for me. :)
Thanks to all of you who took some time to reply and I really
appreciate your help. :)
Bab
Learning Guest
-
Unregistered #17
Re: How to replace first and last "," in a string in asp vbscript?
Function xTrim(lookWhere,trimWhat)
Do While left(lookWhere,len(trimWhat))=trimWhat : lookWhere = right(lookWhere,len(lookWhere)-len(trimWhat)) : Loop
Do While right(lookWhere,len(trimWhat))=trimWhat : lookWhere = left(lookWhere,len(lookWhere)-len(trimWhat)) : Loop
xTrim = lookWhere
end function
Mystring = xTrim(Mystring,",")
Unregistered Guest



Reply With Quote


