473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

format string

Just a little question...

How do I split 12345678 into 12 34 56 78???????
Christopher Brandsdal
Jul 19 '05 #1
9 4463
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" <ch***********@c2i.net> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Just a little question...

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

Jul 19 '05 #2
Thanks!
But is there not a more easy way to do this?

:)
"Yarn" <no**@noaddress.com> skrev i melding
news:e4*************@TK2MSFTNGP12.phx.gbl...
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" <ch***********@c2i.net> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Just a little question...

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


Jul 19 '05 #3

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",8),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" <ch***********@c2i.net> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
Thanks!
But is there not a more easy way to do this?

:)
"Yarn" <no**@noaddress.com> skrev i melding
news:e4*************@TK2MSFTNGP12.phx.gbl...
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" <ch***********@c2i.net> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Just a little question...

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



Jul 19 '05 #4
Christopher Brandsdal wrote on 19 sep 2003 in
"Christopher Brandsdal" <ch***********@c2i.net> wrote in message
> How do I split 12345678 into 12 34 56 78???????
>

"Yarn" <no**@noaddress.com> 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)
Jul 19 '05 #5
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" <no**@noaddress.com> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
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" <ch***********@c2i.net> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Just a little question...

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


Jul 19 '05 #6
"Yarn" <no**@noaddress.com> wrote in message
news:eG*************@TK2MSFTNGP12.phx.gbl...
.. . .
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.
Jul 19 '05 #7
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
Jul 19 '05 #8
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" <P.******@open.ac.uk> wrote in message
news:bk**********@yarrow.open.ac.uk...
"Yarn" <no**@noaddress.com> wrote in message
news:eG*************@TK2MSFTNGP12.phx.gbl...
. . .
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.

Jul 19 '05 #9
'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
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: san | last post by:
Hello, all! I have question about String.Format method. There are two variants: public static string Format(string, params object); and public static string Format(IFormatProvider, string, params...
6
by: Stuart McGraw | last post by:
I am looking for a VBA "format" or "template" function, that is, a function that takes a format string and a varying number of arguments, and substitutes the argument values into the format string...
11
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <=...
2
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double...
7
by: Alpha | last post by:
Hi, I'm maintaining C# code and am fairly new with C# programming. I'm looking for codes that's droping the 2nd digit of a nuber printed out and I suspect it's the code below. Can someone tell me...
4
by: David Morris | last post by:
Hi Could somebody please explain what the following line of code means String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1 It's actually the first argument that I don't understand. What is...
6
by: Scewbedew | last post by:
Suppose I have the following code: string myFormat = "Line1/nLine 2"; string formattedString = string.Format(myFormat); ....that would produce a 2-line output as expected. But if I load...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
7
by: Rick | last post by:
With String.Format, if I have an incorrect number of args specified for a format string, compile fails. How can I implement similar design-time functionality for my own string functions?
8
by: Armando Rocha | last post by:
Hi, Hi have a string with 16 chars "25DD68EDEB8D5E11" and i want show it in form like this "25DD-68ED-EB8D-5E11", i try String.Format("{0:####-####-####-####}", mystr), but not work, i think...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.