|
You can certainly access individual characters out of the internal string value using the Chars property, but I have never run across a situation where that is really useful. Usually StringBuilder is used to save on string allocations when performing a lot of string manipulation with the end result desired being the final string value. By accessing it a character at a time, it isn't much different than building up a char array.
|
|
|
|
|
Scott Dorman wrote: By accessing it a character at a time, it isn't much different than building up a char array
It's dynamic, and one can Insert.
|
|
|
|
|
True, but it seems like there would be better ways to interact with a char array.
|
|
|
|
|
Yeah, but if you want something like StringBuilder but which logically encapsulates "a dynamic array of chars" rather than "a string", would you write one? I wouldn't.
Borrowing from recent discussions of the using directive, one could do:
using CharArrayBuilder=System.Text.StringBuilder ;
|
|
|
|
|
Yes, I agree that it might not be very useful but the question was if it was possible to access individual chars to which you said no. That's why I wrote it
|
|
|
|
|
For example:
Just yesterday I was working on a simple program that reads a C Sharp source file line-by-line then checks and corrects the indentation and such.
After reading a line, I put it in a StringBuilder, then I do things like:
theline.Replace ( '\t' , ' ' ) ;
switch ( theline [ 0 ] ) { ... }
if ( theline [ 1 ] != ' ' ) { ... }
What I dislike about the StringBuilder (as implemented in .net 2 and earlier anyway), is:
A) There is no Clear() method, so I use theline.Remove ( 0 , theline.Length ) ;
B) There is no way to Set the string (after instantiation) other than Append()
Which means I have to use:
while ( ( inline = Infile.ReadLine() ) != null )
{
theline.Remove ( 0 , theline.Length ) ;
theline.Append ( inline ) ;
...
}
If anyone else has a better technique, pleast let me know.
(Does the .net 3 version have more functionality? I'd better check.)
|
|
|
|
|
Hi,
I am afraid they expect you create a new StringBuilder instance in these
situations; they would probably add "who cares about one more object, you have
two already (original string and final string)".
I would not be surprised if a new SB is actually faster than Remove+Append.
And I have the impression you would like to have File.ReadLineToStringBuilder()
avoiding the string object all together.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: I would not be surprised if a new SB is actually faster than Remove+Append.
Great, something else to try out. But I've got to believe a Clear(), which may simply set the Length...... Holy F-ing Dung! Length is not read-only!? Glory Hallelujah! Did no one else know this? Keeping it a secret? Ha ha! PIEBALD didn't RTFM?! Is that it? Well, I found out your little secret, there's no stopping me now!
It does seem to violate something though, Length is read-only for most objects.
Luc Pattyn wrote: And I have the impression you would like to have File.ReadLineToStringBuilder()
I could write a library function that reads the file character-by-character to simulate that, and I may still do so.
As the program stands, I compare the raw line with the resultant line to report which lines were modified, but that'll likely go away.
|
|
|
|
|
PIEBALDconsult wrote: Length is read-only for most objects
so Builders are a special breed...
Now you can still ponder the Length=0; Append(string); versus new SB(string); dilemma.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Well, I'd still rather not have to allocate a new array each time. And the array in use is already expanded to hold the longest line encountered so far (I do allocate it to hold twice my expected maximum, so maybe that's not too much of an issue).
So, I'm reusing the same instance.
And maybe I will fill it one character at a time, but I'm pondering the implementation.
|
|
|
|
|
Hi,
Does any one know of an application that records pixel movement of an application. I.e. take a movie on a application while you work on it.
|
|
|
|
|
Camtasia[^], from the good people who brought us SnagIt. And this[^] is a free alternative.
/ravi
|
|
|
|
|
Thanks,
I was more thinking on how to actually write the code to do it
|
|
|
|
|
I have a data grid and in the first column I have a button. When I click on the button event I new the values that are the ceel next too it.
|
|
|
|
|
i have a checkedListBox and a dataGrid, i want to select anything from the list and click a Btn , so the select item goes to the dataGrid
Regards....
code tips are reqired
|
|
|
|
|
costavo wrote: so the select item goes to the dataGrid
Are you trying to manipulate purely on the JavaScript or after a serverside roundtrip?
|
|
|
|
|
no sir, it is pure c# and workin in a windows app.
|
|
|
|
|
I am busy writing the following code and when I built up a header from Data with the following code:
for (int k = 2; k < components.Length; ++k)
{
SourceGrid.Cells.ColumnHeader header1 = new
SourceGrid.Cells.ColumnHeader(components[k].Phase.FullName);
header1.AutomaticSortEnabled = false;
grid1[0, k] = header1;
grid1[x + 5, k ] = new SourceGrid.Cells.CheckBox("", false);
grid1[x + 5, k ] = new SourceGrid.Cells.CheckBox("", false);
How can I use the following code to spam the header columns:
grid1[0, k].ColumnSpan = 2;
|
|
|
|
|
Brother Louis wrote: spam the header columns
Did you mean span the header columns?
I would suggest instead of manipulating the header, you could have fixated it from the Webform part right?
|
|
|
|
|
Please explain I'm lost what you say. It is "Columnspan"
|
|
|
|
|
Hi,
I have written a webservice the purpose being is to convert the sent docu to pdf.
Steps involved are as follows:
1)The to be converted doc is sent to the webservice in the form of bytes
2)In the web service a file is created using the bytes received.
3)This file is then printed using a printer driver(Nova PDF) which saves the sent file in pdf file in required folder.
4)Then the pdf is opened using filestream and then bytes are sent from the web service to the caller.
Problem occurs when large sized files!
I guess even before the filestream is completely done we are trying to read the file again as a resultant it throws an error:
File cannot be accessed as it is being used by another process....
Is there a way that i could do filestream read only once the pdf document is completely loaded by the printer driver?
Thanks,
gauthee
|
|
|
|
|
Did the Writer object close the Stream and got nulled before the StreamReader attempted to open it?
|
|
|
|
|
There is no writerstream!
On sending the file to the printer driver a pdf file is created and saved in respective folder, after this operation(print operation) then iam trying to open the pdf file using the filestream and at this point it thows error:
file cannot be accessed as it is being used by another process.....
gauthee
|
|
|
|
|
Hi,
if your producer does not signal it is done producing the file, the only
things you can do are:
- wait a very long time;
- or loop {wait a short time; try; exit on success;}
BTW: if the web service is going to send the PDF back to the client, it will
have to delete the file also; that too can fail because the file is being
read by another process (Antivirus, Google desktop, whatever).
The remedy is: loop {try; exit on success; wait a short time;}
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
You can use a FileSystemWatcher for this.
This class is used to monitor a certain folder on the filesystem (disk) where your service runs.
It fires events when something changes to the filesystem (eg. file created, renamed, deleted,...)
Say your PDF printer saves the file as c:\temp\pdf\someName.pdf, then you can monitor the c:\temp\pdf folder with the FileSystemWatcher.
When a file is created in that directory (by your pdf printer) an event is thrown. You can catch this event and
then send the newly generated file.
For more info on this class please visit the MSDN site here[^].
Hope this helps!
Tim Wuytens
|
|
|
|