Hi,
I want modify a string as "1122334455 66" in
"11:22:33:44:55 :66"
which is the best method?
Using a RegExp? and if yes how?
Thanks in advance
Nov 16 '05
14 1501
ok point taken... in this case
StringBuilder sb = new StringBuilder(" 112233445566", 20);
for (int i = 2; i < 15; i += 3)
sb.Insert(i, ":");
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com... Ralf B. <ra*********@mo rtgageuk.com> wrote: i am creating 5 substrings..
your solution works but has a lot of code..
substring() produces temp strings, too. Also, I suppose StringBuilder internally works with temporary strings as well.
StringBuilder uses a temporary string if it needs to be expanded, but if you give it the right size to start with, it shouldn't need any temporary measures.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Ralf B. <ra*********@mo rtgageuk.com> wrote: ok point taken... in this case
StringBuilder sb = new StringBuilder(" 112233445566", 20); for (int i = 2; i < 15; i += 3) sb.Insert(i, ":");
That would certainly be significantly better, yes. Quite possibly
better than all the other suggestions, although it does involve copying
the data around a bit. (Every time you insert something, you need to
copy the rest of the string.)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi,
What about :
StringBuilder sb = new StringBuilder( 20)
int start = 0;
string str = "1122334455 66";
while ( str.Length - start > 2 )
{
if ( start != 0 )
sb.Append( ':' ); // Adding a CHAR
sb.Append( str[ start++] );
sb.Append( str[ start++] );
}
No temp string created :D
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Ralf B. <ra*********@mo rtgageuk.com> wrote: ok point taken... in this case
StringBuilder sb = new StringBuilder(" 112233445566", 20); for (int i = 2; i < 15; i += 3) sb.Insert(i, ":");
That would certainly be significantly better, yes. Quite possibly better than all the other suggestions, although it does involve copying the data around a bit. (Every time you insert something, you need to copy the rest of the string.)
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote: What about:
StringBuilder sb = new StringBuilder( 20) int start = 0; string str = "1122334455 66"; while ( str.Length - start > 2 ) { if ( start != 0 ) sb.Append( ':' ); // Adding a CHAR sb.Append( str[ start++] ); sb.Append( str[ start++] ); }
No temp string created :D
Indeed. I don't know whether the double append is faster than
sb.Append(str, start, 2);
or not.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi,
:)
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... <"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT dot.state.fl.us >> wrote: What about:
StringBuilder sb = new StringBuilder( 20) int start = 0; string str = "1122334455 66"; while ( str.Length - start > 2 ) { if ( start != 0 ) sb.Append( ':' ); // Adding a CHAR sb.Append( str[ start++] ); sb.Append( str[ start++] ); }
No temp string created :D
Indeed. I don't know whether the double append is faster than
sb.Append(str, start, 2);
or not.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing result in any way. Who can
help me, I thank you very very much.
list.cpp(main program)
//--------------------------------------------------------------------------
-
#pragma hdrstop
#pragma argsused
|
by: Alan Bashy |
last post by:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help me.
This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of
our text.
I have done Exercise 7 for you: Below you will find the ADT specification
for a string
of characters. It represents slightly more that a minimal string...
|
by: wukexin |
last post by:
I write my own class Cfile, I want to know what about implement ctime().Who
help me?
My use function ctime, I sign it with $$$.
my class Cfile:
#------------------------
file.h
#---------------------------
#include <io.h>
#include <ctime>
#include <string>
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With numarray, help gives unhelpful responses:
|
by: James Radke |
last post by:
Hello,
I have a multithreaded windows NT service application (vb.net 2003) that I
am working on (my first one), which reads a message queue and creates
multiple threads to perform the processing for long running reports. When
the processing is complete it uses crystal reports to load a template file,
populate it, and then export it to a PDF.
It works fine so far....
| |
by: James Radke |
last post by:
Hello,
We are currently using a user DLL that when working in VB 6.0 has a user
defined type as a parameter.
Now we are trying to use the same DLL from a vb.net application and are
having some problems getting it to work and we don't know why. Basically
the function is accepting the parameters, and then returning an error and
never performing the update.
|
by: Allen |
last post by:
I have a class that returns an arraylist. How do I fill a list box from what
is returned? It returns customers which is a arraylist but I cant seem to
get the stuff to fill a list box. I just learning and really need some help
bad.
Public Shared Function GetAll() As ArrayList
Dim dsCustomer As New DataSet()
Dim sqlQuery As String = "SELECT Name, Address, PhoneNo " & _
"FROM CustomerTable"
Try
|
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am attach this script
files and inq files. I cant understand this error. Please suggest me.
You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online.
Plz....Plz..Plz...
|
by: KitKat |
last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,
and Cam 8. Well it does that but it also needs to change the file name to
the same folder where the file is being grabbed, BUT it doesn't. I have
tried and tried.....please help
example: C:\Projects\Darryl\Queue Review Files\2-24\Cam
7\Cam7-20060224170000-01.jpg
Cam7 but all I keep getting is Cam1, as the beginning of the jpg
name,...:( HELP!
|
by: JonathanOrlev |
last post by:
Hello everyone,
I have a newbe question:
In Access (2003) VBA, what is the difference between a Module and a
Class Module in the VBA development environment?
If I remember correctly, new types of objects (classes) can only be
defined in Class modules.
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |