|
Regex r = new Regex(@"(?<=src="")([^""]+)(?="")");
string s = "<P>Hello</P>\r\n<P> </P>\r\n<P><IMG alt=\"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg\" src=\"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg\"></P>";
string t = r.Replace(s, "new url");
Get a copy of Expresso[^] - examines and generates Regular expressions. It's free and really helps!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hi Friends
I am working with windows application..using C#.
I have and MDI form which have the following variables..
public String FranchisorName = "", FranchiseeName = "", LocationName = "", UserName = "";
public String strlblProcess, strlblBatch;
public String Flag = "";
public String QBFName = "";
public String ConnectionString;
and I wand access these values in another form i.e Child form which has the following code..
public frmMDIMain objMDIMain = new frmMDIMain();
String temp = objMDIMain.ConnectionString;
But I am not able to retirive the value of ConnectionString variable...
please help me out..
thanx in advance..
|
|
|
|
|
That is because when you write
public frmMDIMain objMDIMain = new frmMDIMain(); in your child form it creates a new instance of the MDI main form. You need to access the existing MDI parent, via the MdiParent property instead.
See also DaveyM69's tip on passing data between forms.[^]
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
hey,
i need to fill two dictionaries with data, so i send each dictionary from one class to MultiThreaded Class by ref...
here how it's looks like
public EnglishDataBase()
{
MultiThread mt = new MultiThread();
englishCapLetter = new Dictionary<char, int>();
englishSmallLetter = new Dictionary<char, int>();
Thread t1 = new Thread(new ThreadStart(mt.fillCaps(ref englishCapLetter))));
Thread t2 = new Thread(new ThreadStart(mt.fillUnCaps(ref englishSmallLetter)));
t1.Start();
t2.Start();
t1.Join();
t2.Join();
}
public void fillCaps(ref Dictionary<char, int> englishCapLetter)
{
while (!sr1.EndOfStream)
{
string letter = sr1.ReadLine();
englishCapLetter.Add(char.Parse(letter.ToUpper()), char.Parse(letter.ToUpper()));
}
}
public void fillUnCaps(ref Dictionary<char, int> englishSmallLetter)
{
while (!sr2.EndOfStream)
{
string letter = sr2.ReadLine();
englishSmallLetter.Add(char.Parse(letter.ToLower()), char.Parse(letter.ToLower()));
}
}
but then i get a "Method name expected" in t1 and t2 creation compilation error...
what's wrong with implementation i did ?
tanks in advance
|
|
|
|
|
|
already saw it, that's what i did
thanks any way
|
|
|
|
|
No, that's not what you did. Read more carefully.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
i meant to "that's what i did eventually..."
|
|
|
|
|
You just have to set the name of the method that should run in you thread.
Something like this:
Thread t1 = new Thread(new ThreadStart(mt.fillCaps));
To work with parameter you have to use the ParameterizedThreadStart delegate.
Thread t1 = new Thread(new ParameterizedThreadStart(mt.fillCaps));
Thread t2 = new Thread(new ParameterizedThreadStart(mt.fillUnCaps));
t1.Start(englishCapLetter);
t2.Start(englishSmallLetter);
t1.Join();
t2.Join();
Greetings
Covean
|
|
|
|
|
that's exactly what i did...
and it did work with complex object (Dictionary\instance of class etc...) but when i tried that method with "cooler" object as string, i got null after the thread has stopped running, i tried to debug, and i see that inside the thread the string object does get data from file, but it doesn't give it back to the one who called that thread. i was thinking that ParameterizedThreadStart transfers by ref, was i wrong ?
thanks
p.s
of course, i would like to get some ideas how to solve that issue...
|
|
|
|
|
you don't need the ref keyword, all objects are passed by reference, i.e. their pointer value is shared, so every party involved can modify the object (mind you: modify, not replace).
|
|
|
|
|
then why i cant transfer string object by ref ? it's only transfers by val
|
|
|
|
|
strings (and almost all structs) are immutable, when you think you modify a string, you are actually replacing it by a new string. Most objects are not immutable, so you can pass Forms and Controls and Dictonaries around, modify them, and have the caller see your modifications without limitations.
|
|
|
|
|
Damn, I need to type faster
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: I need to type faster
yes.
or start sooner.
|
|
|
|
|
Too simple. I'll just issue a DoS attack on your servers to prevent you from posting
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
That won't work either, CodeProject just tried that, and all they got was more messages. See my sig.
|
|
|
|
|
As Luc pointed out objects passed by ref are able to be modified. This is because you are working with the memory location of the actual object. Since a string is immutable any time it is modified an new one is created which points to a new memory location, not the original that may have been passed to the method.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
i see...
then i need to wrap this string with other object list for exmp, and to pass list to the thread, after creating new string, return it with the "ref" list, am i right ?
|
|
|
|
|
If you mean to create some object that contains the string and passing it around, then yes, I believe that will work for you. Although more levels of abstraction does not improve anything. Possibly you could re-engineer the code so it is not necessary?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
it did work for me...
and yes, i can re-engineer the code, but it means that i will work in single thread mode... i wanted to practice on multithreading...
|
|
|
|
|
Re-engineering doesn't necessarily mean you have to give up on multithreading, just use it differently
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I have 2 forms.
both are loaded.
i wanat with click in Datagrid cell string display in Text box in Other FORM
hoW can i do?
|
|
|
|
|
Raise an event in the form that has the DataGrid in it, and subscribe to the event in the other form.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
If I had received a penny everytime this question was asked here...
|
|
|
|