循环:
var pattern = _dict[key];
string before;
do
{
before = pattern;
foreach (var pair in _dict)
if (key != pair.Key)
pattern = pattern.Replace(string.Concat("{", pair.Key, "}"), string.Concat("(", pair.Value, ")"));
} while (pattern != before);
return pattern;
Run Code Online (Sandbox Code Playgroud)
它只是在一堆键上重复查找和替换.字典就是<string,string>.
我可以看到2个改进.
pattern.Replace再次从字符串的开头搜索.如果当它达到第一个时{,它会更好地查看匹配的键列表(可能使用二进制搜索),然后替换适当的键.pattern != before位是我如何检查在迭代期间是否有任何替换.如果pattern.Replace函数返回了实际发生的实际替换次数或替换次数,我就不需要了.但是......我真的不想写一个很讨厌的东西来做所有这些.这必须是一个相当常见的场景?有没有现成的解决方案?
感谢Elian Ebbing和ChrisWue.
class FlexDict : IEnumerable<KeyValuePair<string,string>>
{
private Dictionary<string, string> _dict = new Dictionary<string, string>();
private static readonly Regex _re = new …Run Code Online (Sandbox Code Playgroud) 我使用以下代码将密钥转换为字节
SecretKey key = KeyGenerator.getInstance("DES").generateKey();
byte[] bkey=key.getEncoded();
Run Code Online (Sandbox Code Playgroud)
现在如何从中获取密钥bkey?我试过了:
SecretKeySpec secretkey = new SecretKeySpec(bkey,"DES");
SecretKeyFactory sfkey = SecretKeyFactory.getInstance("DES");
SecretKey skey = sfkey.generateSecret(secretkey);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error during Exception java.security.spec.InvalidKeySpecException: Inappropriate key specification
Run Code Online (Sandbox Code Playgroud) 我买了一台新的MacBook Pro并按顺序安装了下面的应用程序列表.在我的旧MacBook上,也运行OS X 10.6.6,但我没有/usr/bin/git在新款MacBook Pro上运行.我能想到的两个系统之间的唯一区别是:
自制软件安装git 1.7.4.1 /usr/local/Cellar/git并将其符号化/usr/local/bin.这让我相信Xcode 4安装了git1.7.3.4 /usr/bin.任何人都可以确认或否认这个吗?
如果Xcode 4没有安装git 1.7.3.4 /usr/bin,那么有什么想法程序呢?
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"brew install gitbrew install …我使用asp.net和Web表单.在我的项目中,我有asmx web服务
[WebMethod]
public string GetSomething()
{
// avoid circual reference(parent child)
List<RetUsers> res = repo.GetAllUser().Select(c => new RetUsers {User_ID = c.User_ID,User_Name = c.User_Name,Date_Expire = c.Date_Expire }).ToList();
string res1 = res.ToJson();
// extension methods
return res.ToJson();
}
Run Code Online (Sandbox Code Playgroud)
结果就是这种格式.
[
{"User_ID":1,"User_Name":"Test 1","Date_Expire":null},
{"User_ID":2,"User_Name":"Test 2","Date_Expire":null}
]
Run Code Online (Sandbox Code Playgroud)
如何在$ .ajax sucess中附加标记此结果以获得此输出:
1 - 测试1,2 - 测试2.
好的,所以我知道这有点不对,但我错过了什么?代码是用以下单词旋转单个字母:
rotate 1 "hello" "ohell"
rotate -1 "hello" "elloh"
Run Code Online (Sandbox Code Playgroud)
我的代码是:
module Main where
import System
main = do
(arg1:_) <- getArgs
xs <- getContents
putStr (rotate xs arg1)
rotate input w1 = unlines [ process line | line <- lines input ]
where process line = unwords [ word | word <- words line ]
map rotate n xs = drop n xs ++ take n xs
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是否正确,任何线索/提示下一步去哪里?
所以有点像这样:
shift :: a -> Int -> a
rotate :: a -> …Run Code Online (Sandbox Code Playgroud) 我正在使用Skype4COM控件.我的程序试图使用For循环从Skype中的联系人列表中删除大约3K联系人
1)这需要很多时间
2)它可能会崩溃,"MyApp已停止工作"
我的猜测是,我需要"减慢"我正在做的事情.
我会用Sleep()来做那件事吗?因为我不确定这是否会"暂停"Skype和我的程序之间的连接.
总结一下:我正在用大量的条目做一个动作,由于这个大的数量,我的程序挂了很长时间,并最终崩溃(有时).有办法防止这种情况吗?
Skype4COM顺便提一下STA.
为什么DisplayUsers();不起作用?
我的基页是:
public class adminPage : System.Web.UI.Page
{
protected override void OnLoad(EventArgs e)
{
if (User.Identity.IsAuthenticated == false) { Response.Redirect("~/Account/login.aspx?ReturnUrl=/admin"); };
if (!(User.IsInRole("admin") || User.IsInRole("super user"))) { Response.Redirect("/"); };
}
}
Run Code Online (Sandbox Code Playgroud)
我的班级是
public partial class users : adminPage
{
protected void Page_Load(object sender, EventArgs e)
{
string sName;
adminGeneralData.GetToolData(2, out sName);
pageH1.Text = sName;
DisplayUsers();
}
protected void DisplayUsers()
{
DataSet ds = userData.GetUsersData();
userList.DataSource = ds;
userList.DataBind();
}
}
Run Code Online (Sandbox Code Playgroud)
但DisplayUsers()不起作用,
例如,我有这个表:
itemgroup | 描述| 价格
A,a,10
A,b,12
A,c,14
B,g,11
B,h,16
现在我想在一个组中选择价格最高的行,如下所示:
A,c,14
B,h,16
SQL查询(功能齐全)让我接近这个:
SELECT itemgroup, MAX( price )
FROM table
GROUP BY itemgroup
Run Code Online (Sandbox Code Playgroud)
A,14
B,16
通过尝试这个我得到一个"不是GROUP BY表达式"-error:
SELECT itemgroup, description, MAX( price )
FROM table
GROUP BY itemgroup
Run Code Online (Sandbox Code Playgroud)
我需要像这样的伪查询:
SELECT itemgroup, IGNORE( description), MAX( price )
FROM table
GROUP BY itemgroup
Run Code Online (Sandbox Code Playgroud)
我希望我能解释一下我的小问题.
假设我有N个成员的课程.大多数成员都是可复制的.只有一个成员需要手动复制代码.
是否有方法以这样的方式编写复制赋值运算符,即我只为非标准成员编写代码,并让编译器为所有/其他成员生成复制代码?
我从我的主要NSWindow开了一个NSWindow.
DropHereWindowController *dropHereWindowController = [[DropHereWindowController alloc] initWithWindowNibName:@"DropHereWindow"];
[dropHereWindowController showWindow:nil];
Run Code Online (Sandbox Code Playgroud)
将文件从finder拖到"DropHereWindow"时,我希望此窗口保持在主窗口的顶部.然而,当打开取景器(不再有焦点)时,我的"DropHereWindow"就在我的主窗口后面.
我尝试了orderFront,makeKey,makeKeyAndFront,但没有任何帮助.我能做些什么呢?