Jump to content

Wikipedia:Reference desk/Archives/Computing/2016 July 27

From Wikipedia, the free encyclopedia
Computing desk
< July 26 << Jun | July | Aug >> July 28 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


July 27

[edit]

Some C# help needed

[edit]

Hi guys! Could somebody help out with C#? If I have regex pattern ([^\.])<ref>.*?<\/ref> (Lorem|Foo)? bar and string "Foo<ref>Foo</ref> Foo bar", how to change to lowercase only the second match (in this case - the "Foo", that comes after ref)? If I would need to lowercase everything, I would use something like (tested with other string, so this one may contain some small bugs, but you got the idea):

	string text = @"Foo<ref>Foo</ref> Foo bar";
	string pattern = @"([^\.])<ref>.*?<\/ref> (Lorem|Foo)? bar";
	
	text = Regex.Replace(text, pattern, delegate(Match match)
	{
	    string v = match.ToString();
	    return v.ToLower();
	});

Note, that this is for AWB module, so it might not look very C#-ish. --Edgars2007 (talk/contribs) 09:16, 27 July 2016 (UTC)[reply]

Maybe Trappist the monk could take a look - you have also worked with AWB modules. --Edgars2007 (talk/contribs) 11:28, 28 July 2016 (UTC)[reply]
Try this:
	string text = @"Foo<ref>Foo</ref> Foo bar";
	string pattern = @"([^\.])<ref>.*?<\/ref> (Lorem|Foo)? bar";
	
	text = Regex.Replace(text, pattern, delegate(Match match)
	{
	    return match.Groups[2].Value.ToLower();	// second capture to lower case
	});
Not tested, but I've used this construct before.
Trappist the monk (talk) 11:55, 28 July 2016 (UTC)[reply]
@Trappist the monk: it kind of works. String after this becomes "Fofoo". Yes, that is what I was expecting to see after running this code, but not what I wanted to get ("Foo<ref>Foo</ref> foo bar"). --Edgars2007 (talk/contribs) 12:44, 28 July 2016 (UTC)[reply]
Perhaps this then:
	string text = @"Foo<ref>Foo</ref> Foo bar";
	string pattern = @"([^\.]<ref>.*?<\/ref> )(Lorem|Foo)?( bar)";	// captures modified
	
	text = Regex.Replace(text, pattern, delegate(Match match)
	{
	    return match.Groups[1].Value + match.Groups[2].Value.ToLower() + match.Groups[3].Value;	// second capture to lower case
	});
Again, not tested. Regex.Replace replaces all of text with whatever you return from the delegate(), right? If you want to keep bits of text then you need to capture them, modify the captures to suit, reassemble, and return the result. match.Groups[0] is the raw match; match.Groups[1] is the first capture, etc.
Trappist the monk (talk) 13:24, 28 July 2016 (UTC)[reply]
@Trappist the monk: I thought, that there will be easier solution, but this one works, so thank you! --Edgars2007 (talk/contribs) 17:35, 28 July 2016 (UTC)[reply]

xwp file

[edit]

How do I install a .xwp file? Can someone help me please? I collected some clock gadgets a while back from this website. After downloading and opening the WinRar folder, I found a .xwp file - if I re-extract this .xwp file, I find a Widget folder which consisting all the bits. Problem is I still don't know how to install... -- Apostle (talk) 18:12, 27 July 2016 (UTC)[reply]

Your link goes to Google Images and doesn't open any particular image for me. You need to link to the actual web site, not Google Images.
After 60 seconds of research (googling "xwp gadget") I found XWidget which seems to use .xwp files, so maybe that's what you need. I know nothing about it, though. -- BenRG (talk) 23:27, 28 July 2016 (UTC)[reply]