Wikipedia:Reference desk/Archives/Computing/2016 July 27
{{#ifeq:{{PAGENAME}}|Special:Undelete| |{{#if:|
Some C# help needed
Hi guys! Could somebody help out with C#? If I have regex pattern
and string "
", 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 = @"FooFoo Foo bar";
string pattern = @"([^\.]).*?<\/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)
:Maybe {{u|Trappist the monk}} could take a look - you have also worked with AWB modules. --Edgars2007 (talk/contribs) 11:28, 28 July 2016 (UTC)
::Try this:
string text = @"FooFoo Foo bar";
string pattern = @"([^\.]).*?<\/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)
:::{{ping|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 ("
::::Perhaps this then:
string text = @"FooFoo Foo bar";
string pattern = @"([^\.].*?<\/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)
:::::{{ping|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)
''xwp'' file
How do I install a .xwp file? Can someone help me please? I collected some clock gadgets a while back from [https://www.google.com.bd/search?q=clock+gadget+PC+deviantart&source=lnms&tbm=isch&sa=X&ved=0ahUKEwi-5f-wvpPOAhWJo48KHbMBAvsQ_AUICCgB&biw=1366&bih=643 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)
: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 [http://www.xwidget.com/ 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)