|
amitshan wrote: what is the code for..
Wow. Can't do your own code? Google on how to add a ruler to the toolbar, learn how to code it.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi all
I have a problem in counting/extracting matches from a URL string using Regex:
My URL looks like this:
www.website.com/LanguageName/BookName/filename.txt
I use the following code to extract Language name and Bookname:
Match bookMatch = Regex.Match(requestString, "/[^/]*/[^$]", RegexOptions.RightToLeft);<br />
BookInfo bookInfo = new BookInfo();<br />
if (bookMatch.Success)<br />
{ <br />
bookInfo.BookName = bookMatch.Groups[0].Value.Substring(1, bookMatch.Groups[0].Value.Length - 3);<br />
Match langMatch = bookMatch.NextMatch();<br />
if (langMatch.Success)
{<br />
bookInfo.Langauge = langMatch.Groups[0].Value.Substring(1, langMatch.Groups[0].Value.Length - 3); <br />
}<br />
<br />
}<br />
return bookInfo;
Now the code successfully extracts Bookname as it is rightmost in the expression, let us assume that we have the following URL:
www.website.com/LanguageName/BookName/filename.txt
bookMatch will match "/BookName/f", so I remove the 1st one and last two characters to get the bookname correctly.
Now the langMatch doesn't catch the language in the string which should be "/LanguageName/B", it seems that this is happening becoz the 1st match (right to left) has ended at the slash "/" before the BookName, so the search for the next Match will begin on the "e" (last char) character of the LanguageName which will not result in a match.
So how to force the search for the next match to begin on the "/" between the "B" and the "e"?
Any ideas? thanks.
And ever has it been that love knows not its own depth until the hour of separation
Mohammad Gdeisat
|
|
|
|
|
Unfortunately I can't help you with this problem, but why don't you use the Uri class to extract the necessary parts of the URL?
You can use this code:
Uri url = new Uri(@"http://www.website.com/LanguageName/BookName/filename.txt");
string languageName = url.Segments[1];
string bookName = url.Segments[2];
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Excellent, I didn't know about this class
However, if anybody knows how to do it using a Regex then I would be glad to know
Thanks mate
And ever has it been that love knows not its own depth until the hour of separation
Mohammad Gdeisat
|
|
|
|
|
In your case this regex will work, but you have to carefully test it with other URLs:
[^/]/(?<LanguageName>[^/]+)/(?<BookName>[^/]+)/
And some code:
Regex regex = new Regex(@"[^/]/(?<LanguageName>[^/]+)/(?<BookName>[^/]+)/");
Match match = regex.Match(@"www.website.com/LanguageName/BookName/filename.txt");
if (match.Success)
{
string languageName = match.Groups["LanguageName"]);
string bookname = match.Groups["BookName"]);
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
What you are looking for is the concept of a lookahead and lookbehind. This pattern should work:
(?<=/)[^/]*(?=/)(?<!$)
I would suggest looking at the documentation to fully understand how lookahead/behind expressions work. Here's a link to get started:MSDN
|
|
|
|
|
Hi, this is silly
How can i force the write in the next line/row?
No Picture Available
No Picture
Available
Thanks
|
|
|
|
|
<br />
Label1.Text = "Line1\nLine2";<br />
|
|
|
|
|
Environment.NewLine
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
this.label1.Text="line 1"+Convert.ToChar(10)+Convert.ToChar(13)+"Line 2";
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
It's not clear to me how I am expected to use Queue Synchronization.
Is this a general state, which makes the Queue thread safe? Or is this a short, temporary measure I use to lock the queue before I read or write it, and immediately release it when I'm done?
The documentation and samples are too short and don't go into detail on this.
So my question is: do I simply wrap my Queue with a synchronized wrapper and leave it on, doing all further access through that wrapper?
Or do I only wrap the Queue when I'm accessing it, and immediately drop the wrapper when I'm done?
Do I pass the wrapper to other objects, or only the original Queue?
Thanks for any help here.
|
|
|
|
|
Once you call Synchronized(), you should use the returned wrapper
everywhere you would have used the original unsynchronized queue.
Use of the queue through the wrapper will be thread safe for all
"single operation" methods on the queue.
Make sure Synchronized() is really what you need for a thread safe queue.
Enumerating and indexing the queue aren't going to be thread safe
so you may need additional locks.
Making your own thread safe wrapper (or derived) queue class can
be better in some situations. It allows you to implement locks
the way you need to (like using a ReaderWriterLockSlim for producer/consumer
thread access) and provide properly locked enumerating methods.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the response. Okay, so the Sync wrapper persistently replaces the Q itself, and it is the object I should pass around between methods, etc. That was not entirely clear to me before.
This should probably work for what I'm doing; I spawn a listener object on a new thread, which listens for events from a COM object. My main thread passes various Queues to the spawned object (actually, sets them as properties), and the spawned object, when it receives messages, puts a notation in the queue(s).
My main thread polls the queue, dequeuing any notations it finds.
So there's no enumerating or indexing, I think. Of course, I haven't written it yet...
|
|
|
|
|
Multiple writer threads and a single reader thread, right?
The Synchronized() queue should indeed be fine for that.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have a navigation board(ToolStrip object) above a DataGridView object
I use this code to get data from it.
ToolStripTextBox_Row.Text = DataGridView_Country[0, grid_index].Value.ToString();
Ok, now i want to press Button_NextRow (in navigation board) and
set focus to next row in the DataGridView.
How can i do this?
|
|
|
|
|
It is currently displaying the stack upside down, the contents of the top of the stack are displayed as the last line in the text box. I am trying to make this code display the contents of the stack at the top of the text box.
private void displayStack()
{
string nextItem;
displayBox.Clear();
for (int i = 0; i <= stackTop; i++)
{
nextItem = stackArray[i].ToString();
displayBox.AppendText(nextItem);
displayBox.AppendText("\n");
}
}
|
|
|
|
|
Just loop the other way.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
How do I do that?
|
|
|
|
|
private void displayStack()
{
string nextItem;
displayBox.Clear();
// doing it the other way like guffa said
for (int i = stacktop; i >= 0; i--)
{
nextItem = stackArray[i].ToString();
displayBox.AppendText(nextItem);
displayBox.AppendText("\n");
}
}
instead of starting from bottom value of your stack,(originally your intial conditon is int i = 0) you are now starting at the max value of your stack.
Instead of stopping the loop when your variable "i" reaches "stacktop" (top of your stack), the loop stopped at "i = 0"(bottom of your stack).
Because of the above 2 statements, i++ have to change to i-- since you are starting from top to bottom now.
|
|
|
|
|
Thank you Lim and Guffa.It is now working exactly that way. Thank you so much!!!
|
|
|
|
|
Hi Friends
I got a task from my team lead to create a desktop news ticker.
If any one have code or else an helpfull link for the same, please reply back. Thanks in advance.
|
|
|
|
|
|
You need to fix the sign-up. Not working
|
|
|
|
|
What have you done so far, idea-wise?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I am doing research on it, I have not yet started writing code.
What actually I need is a scrolling text on my desktop which must not be a usual text but link and when any of the link is clicked, it should navigate to that particular page
|
|
|
|