|
Colin's right about command-line parameters, but if you want to pass settings specifically, you should use a .config file (in the form, yourappname.exe.config) and use either the <appSettings> section or make your own using IConfigurationSectionHandler . Use that as a keyword to search the CodeProject articles for a slew of examples. This is a better way since if is directly supported by the CLR and the class library, as well as maintains all settings for an application (even ones that you're application doesn't use directly, like assembly bindings) in one file.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
That's the first one that came to mind! I just thought a search would pull up some alternatives that may provide some other ways of doing things or specific examples he might be interested in.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have not hardly cut my teeth on RegEx yet. What I am trying to figure out is a way to replace line feeds with < BR >'s but not between of < PRE > and < /PRE > tags. Any easy answer to do with with RegEx?
Rocky <><
www.HintsAndTips.com
|
|
|
|
|
This is possible using regex with a multi-line expression, but if you're working with HTML you probably shouldn't do this. What if an element spans multiple lines and you replace the new line with <BR> ? You cause HTML errors that browsers will choke on. Putting breaks after inline images would also be bad, since it would screw up the flow of the image with the paragraph that surrounds it. There are several other cases where this would be bad, too.
To better help you solve this problem, let me ask why you want to do this? If you're generating the HTML files, it would be better to do this in the first place, or if you want to modify the files you should use a good HTML reader (unfortunately there isn't a specific reader in the base class library for HTML, though there is the HtmlTextWriter ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have text input via a multipe line TextBox and onces I Server.HTMLEncode it, I need to add the <BR>s for linefeeds. In a specially flagged section though I will be using a < Pre > tag and it requires linefeeds instead of the <BR>s. There are no HTML tags in any of the text entered, just a special tag which I will replace with < Pre > section.
This is for my HintsAndTips.com site that I will FINALLY be launching tonight (and hopefully, people will like posting tips to share since there are only a couple at the moment ). When they post their tips I have to have a special section for things such as code that you do not want text wraping and handle this through a special tag people can use to enclose that section. It is replaced with a scrollable div and a pre tag (to be more compatible with old IEs or would just use the "white-space" css feature).
At the moment I have it replacing all the linefeeds with <BR>s and they look okay in the browser, but the < Pre > does not handle blank lines and stacks the lines on top of each other.
I will be providing a better method of composing tips in the near future, but just needed something to allow people to display text that is much wider then the area provided and a scrollable div works great for that. Kind of like on CP when someone does not format an article good and it takes three monitors to view it horizonally Did not want that happening
Here is an example of tip with the Pre section I was referring to:
http://www.hintsandtips.com/hat.aspx?P=ShowTip&C=31&T=10[^]
Please excuse the home page at the moment, it will be created later tonight
Rocky <><
www.HintsAndTips.com
|
|
|
|
|
I'm teaching myself C# at present and I have hit a wall!
I need to be able to locate a specific string within a file (not a text file, an excel file) and replace it with another. The two strings may not be the same length.
I can open the filestream and open a binaryreader on it but am stuck from there.
Does anyone have any suggestions, or better still some example code I can learn from??
Many thanks, in advance,
Chris
|
|
|
|
|
cgcrute wrote:
I can open the filestream and open a binaryreader on it but am stuck from there.
What is your code? So we can better help you.
Mazy
No sig. available now.
|
|
|
|
|
I didn't include the code I had come up with as it amounts to 2 lines! Don't forget I'm starting out - although I have worked miracles so far!
Here's the code anyhow, for what it's worth:
FileStream reportFile = new FileStream(saveFileDialog1.FileName, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
BinaryReader reportBin = new BinaryReader(reportFile);
|
|
|
|
|
The think that I can see is BinaryReader is for reading but you create FileStream in ReadWrite mode,change it to Read mode,and for writng into create another stream. If it didn't solved then tell what error you encounter. Also in msdn there are some samples for writing into and reading from file in BinaryReader page,you can check it.
Mazy
No sig. available now.
|
|
|
|
|
That isn't so much the problem, but I'll certainly take your advice and use separate streams for reading and writing.
The issue I have is getting the content of the stream into a format that I can use something like regex on to do the search/replace.
I'll check the msdn site too...
Many thanks
|
|
|
|
|
Why don't you manipulate your excel file using Excel Automation?
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
m a y s a m wrote:
Why don't you manipulate your excel file using Excel Automation?
He said he is teaching himself C#,so maybe its just a practise for himself.
Mazy
No sig. available now.
|
|
|
|
|
|
That's the problem Jonathan - I cannot work out how to get the filestream into a format regex will work with.
|
|
|
|
|
Sorry about this lame answer. In fact, RegEx does not accept streams but only strings!
If it is an option, load the entire file to memory and the apply RegEx on it.
Jonathan de Halleux.
www.dotnetwiki.org
|
|
|
|
|
unfortunately loading the whole file seemed to take way too long.
|
|
|
|
|
Look at the next C++ code:
1) Defining map
const int cols=15;
struct stTot {
string strDesc;
double fTots[cols];
} myTot;
map<int, sttot=""> mpLis;
map<int, sttot="">::iterator it;
2) Loading map
int iCnt = 0;
myTot.strDesc = (LPCTSTR)some_string;
for (int v=0; j
|
|
|
|
|
Do me a favor and modify your post.
This time, click the "Do not treat <'s as HTML tags" checkbox.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
See System.Collections.Hashtable .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Does anyone know how i can send messages to other windows applications. For example to tell the media player to start playing a file.
|
|
|
|
|
|
To expand on what Niels said, you'll want to P/Invoke that API:
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(
IntPtr hWnd,
uint msg,
IntPtr wParam,
IntPtr lParam); There are some shortcuts, too. If a param takes an address of a struct, rather than make several unsafe calls from the System.Runtime.InteropServices namespace, you can instead overload SendMessage . For instance, the TVM_SETITEM message for a TreeView Common Control (which System.Windows.Forms.TreeView encapsulates) requires the address of an <code>LPTVITEM for the lParam . You could overload SendMessage like so:
[DllImport("user32.dll")]
private static extern IntPtr SendMessage)
IntPtr hWnd,
uint msg,
IntPtr wParam,
ref LVITEM lvItem); You'll still have to define the LVITEM struct, but this is pretty easy to do. See more information about that in the StructLayoutAttribute documentation.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
How can I get the list of the running applications in my PC,using C#?
Thanks
|
|
|
|
|