Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > format string

Reply
Thread Tools

format string

 
 
Christopher Brandsdal
Guest
Posts: n/a
 
      09-19-2003
Just a little question...

How do I split 12345678 into 12 34 56 78???????


Christopher Brandsdal


 
Reply With Quote
 
 
 
 
Yarn
Guest
Posts: n/a
 
      09-19-2003
You could try this, although it's a little funky-


counter = 2
myString = "12345678"
WHILE counter <= 8
response.write right(left("12345678",counter),2)&"<br>"
counter=counter+2
WEND



"Christopher Brandsdal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Just a little question...
>
> How do I split 12345678 into 12 34 56 78???????
>
>
> Christopher Brandsdal
>
>



 
Reply With Quote
 
 
 
 
Christopher Brandsdal
Guest
Posts: n/a
 
      09-19-2003
Thanks!
But is there not a more easy way to do this?




"Yarn" <(E-Mail Removed)> skrev i melding
news:(E-Mail Removed)...
> You could try this, although it's a little funky-
>
>
> counter = 2
> myString = "12345678"
> WHILE counter <= 8
> response.write right(left("12345678",counter),2)&"<br>"
> counter=counter+2
> WEND
>
>
>
> "Christopher Brandsdal" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Just a little question...
> >
> > How do I split 12345678 into 12 34 56 78???????
> >
> >
> > Christopher Brandsdal
> >
> >

>
>



 
Reply With Quote
 
Yarn
Guest
Posts: n/a
 
      09-19-2003

Probably. This really all there is to it though-

response.write right(left("12345678",2),2)&"<br>"
response.write right(left("12345678",4),2)&"<br>"
response.write right(left("12345678",6),2)&"<br>"
response.write right(left("12345678",,2)&"<br>"

First we grab the two over from the left, than two over from the right.
Than we grab the fourth over from the left, than two over from the right.
and so on..





"Christopher Brandsdal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks!
> But is there not a more easy way to do this?
>
>
>
>
> "Yarn" <(E-Mail Removed)> skrev i melding
> news:(E-Mail Removed)...
> > You could try this, although it's a little funky-
> >
> >
> > counter = 2
> > myString = "12345678"
> > WHILE counter <= 8
> > response.write right(left("12345678",counter),2)&"<br>"
> > counter=counter+2
> > WEND
> >
> >
> >
> > "Christopher Brandsdal" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Just a little question...
> > >
> > > How do I split 12345678 into 12 34 56 78???????
> > >
> > >
> > > Christopher Brandsdal
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-19-2003
Christopher Brandsdal wrote on 19 sep 2003 in
>> "Christopher Brandsdal" <(E-Mail Removed)> wrote in message
>> > How do I split 12345678 into 12 34 56 78???????
>> >

> "Yarn" <(E-Mail Removed)> skrev i melding
>> You could try this, although it's a little funky-
>>
>> counter = 2
>> myString = "12345678"
>> WHILE counter <= 8
>> response.write right(left("12345678",counter),2)&"<br>"
>> counter=counter+2
>> WEND

>
> But is there not a more easy way to do this?


<%
myString = "12345678"
Set regEx = New RegExp
regEx.Pattern = "(..)(?=.)"
regEx.Global = True
newString = regEx.Replace(myString, "$1 ")

response.write newString & "<br>"
%>

============================================

Works for any length any char.

The (..) selects to char's,
that are replaced "$1 " by the same plus a space.

The (?=.) looks ahead for another char,
so that an end space is suppressed.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Phill. W
Guest
Posts: n/a
 
      09-19-2003
"Yarn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
.. . .
> response.write right(left("12345678",2),2)&"<br>"

.. . .

(Yes, it's /definitely/ VBScript, so...)

What, pray tell, is wrong with using Mid() ???

sData = "12345678"
Response.Write Mid( sData, 1, 2 ) _
& " " & Mid( sData, 3, 2 ) _
& " " & Mid( sData, 5, 2 ) _
& " " & Mid( sData, 7, 2 )

Regards,
Phill W.


 
Reply With Quote
 
Tom B
Guest
Posts: n/a
 
      09-19-2003
myString="12345678"
Dim iLoop
for iLoop = 1 to len(myString) Step 2
Response.write mid(myString,iLoop,2)
next

'Untested....but it should work


"Yarn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You could try this, although it's a little funky-
>
>
> counter = 2
> myString = "12345678"
> WHILE counter <= 8
> response.write right(left("12345678",counter),2)&"<br>"
> counter=counter+2
> WEND
>
>
>
> "Christopher Brandsdal" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Just a little question...
> >
> > How do I split 12345678 into 12 34 56 78???????
> >
> >
> > Christopher Brandsdal
> >
> >

>
>



 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      09-21-2003
Try this test to make your decision on what to do.


<%
strString = "12345678"
start = Timer()
For i = 1 To 1000
RexEx(strString)
Next
response.write "RegularExpersion = " & GetTime(start) & "<br>"
start = Timer()
For i = 1 To 1000
MidLoop(strString)
Next
response.write "MidLoop = " & GetTime(start) & "<br>"
start = Timer()
For i = 1 To 1000
MidHardCode(strString)
Next
response.write "MidHardCode = " & GetTime(start) & "<br>"
start = Timer()
For i = 1 To 1000
ArrayBreak(strString)
Next
response.write "ArrayBreak = " & GetTime(start) & "<br>"

Function GetTime(start)
GetTime = FormatNumber(Timer() - start,4)
End Function

Function MidLoop(strData)
for iLoop = 1 to len(strData) Step 2
MidLoop = mid(strData,iLoop,2) & " "
next
End Function

Function MidHardCode(strData)
MidHardCode = Mid( strData, 1, 2 ) _
& " " & Mid( strData, 3, 2 ) _
& " " & Mid( strData, 5, 2 ) _
& " " & Mid( strData, 7, 2 )
End Function

Function RexEx(strData)
Set regEx = New RegExp
regEx.Pattern = "(..)(?=.)"
regEx.Global = True
RexEx = regEx.Replace(strData, "$1 ")
End Function

Function ArrayBreak(strData)
Dim aryData()
intLen = Len(strData)
If intLen > 0 Then
ReDim aryData((intLen \ 2) + 1)
intCount = 0
for iLoop = 1 to len(strData) Step 2
strItem = Trim(mid(strData,iLoop,2))
If Len(strItem) > 0 Then
aryData(intCount) = strItem
intCount = intCount + 1
End If
next
ArrayBreak = Trim(Join(aryData," "))
End If
End Function
%>


--
-dlbjr

Discerning resolutions for the alms


 
Reply With Quote
 
Yarn
Guest
Posts: n/a
 
      09-21-2003
I liked my first one better.
Keeps my clients from trying to hack my code themselves.
Obsfucating is the key to long term clients!

(what a weasel, I know..)

counter = 2
myString = "12345678"
WHILE counter <= 8
response.write right(left("12345678",counter),2)&"<br>"
counter=counter+2
WEND








"Phill. W" <(E-Mail Removed)> wrote in message
news:bkes24$l44$(E-Mail Removed)...
> "Yarn" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> . . .
> > response.write right(left("12345678",2),2)&"<br>"

> . . .
>
> (Yes, it's /definitely/ VBScript, so...)
>
> What, pray tell, is wrong with using Mid() ???
>
> sData = "12345678"
> Response.Write Mid( sData, 1, 2 ) _
> & " " & Mid( sData, 3, 2 ) _
> & " " & Mid( sData, 5, 2 ) _
> & " " & Mid( sData, 7, 2 )
>
> Regards,
> Phill W.
>
>



 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      09-21-2003
'Here is a timing test

<%
strString = "12345678"
start = Timer()
For i = 1 To 1000
RexEx(strString)
Next
response.write "RegularExpersion = " & GetTime(start) & "<br>"
start = Timer()
For i = 1 To 1000
MidLoop(strString)
Next
response.write "MidLoop = " & GetTime(start) & "<br>"
start = Timer()
For i = 1 To 1000
MidHardCode(strString)
Next
response.write "MidHardCode = " & GetTime(start) & "<br>"
start = Timer()
For i = 1 To 1000
ArrayBreak(strString)
Next
response.write "ArrayBreak = " & GetTime(start) & "<br>"

Function GetTime(start)
GetTime = FormatNumber(Timer() - start,4)
End Function

Function MidLoop(strData)
for iLoop = 1 to len(strData) Step 2
MidLoop = mid(strData,iLoop,2) & " "
next
End Function

Function MidHardCode(strData)
MidHardCode = Mid( strData, 1, 2 ) _
& " " & Mid( strData, 3, 2 ) _
& " " & Mid( strData, 5, 2 ) _
& " " & Mid( strData, 7, 2 )
End Function

Function RexEx(strData)
Set regEx = New RegExp
regEx.Pattern = "(..)(?=.)"
regEx.Global = True
RexEx = regEx.Replace(strData, "$1 ")
End Function

Function ArrayBreak(strData)
Dim aryData()
intLen = Len(strData)
If intLen > 0 Then
ReDim aryData((intLen \ 2) + 1)
intCount = 0
for iLoop = 1 to len(strData) Step 2
strItem = Trim(mid(strData,iLoop,2))
If Len(strItem) > 0 Then
aryData(intCount) = strItem
intCount = intCount + 1
End If
next
ArrayBreak = Trim(Join(aryData," "))
End If
End Function
%>


--
-dlbjr

Discerning resolutions for the alms


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: raw format string in string format method? Chris Angelico Python 3 03-01-2013 12:00 AM
Re: raw format string in string format method? Rick Johnson Python 0 02-28-2013 11:06 PM
Re: raw format string in string format method? Peter Otten Python 0 02-28-2013 03:41 PM
Simple error : method format(String, Object[]) is not applicable for the arguments (String, String) ankur Java 1 08-27-2007 06:31 AM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM



Advertisments