小编Nag*_*aga的帖子

在哈希表范围内查找密钥的最佳算法

问题

从下面的项目列表我将需要通过识别具有给定值的键范围来访问该项目,例如,假设值为2.1.1,这是度,分和秒我需要找到键0.0.0-30.0.0性能是高优先级.

key: 0.0.0-30.0.0   value: x-y-z
key: 30.0.0-60.0.0  value: y-x-z
key: 60.0.0-90.0.0  value: z-y-z
Run Code Online (Sandbox Code Playgroud)

解决方案1: 到目前为止我尝试过以下解决方案

重新创建新的键/值(json)文件,如下所示

key: 0.0.0  value: x-y-z
key: 0.0.1  value: x-y-z
.
key: 0.0.59 value: x-y-z
.
key: 0.1.0 value x-y-z
key: 0.1.1 value x-y-z

key: 30.0.0  value: y-x-z
.
.
key: 30.0.59 value: y-x-z
.
key: 30.1.0 value: y-x-z
key: 30.1.1 value: y-x-z
key: 30.1.2 value: y-x-z
.
.
key: 30.1.59 value: y-x-z
key: 30.2.0 value: y-x-z
key: 30.2.1 value: y-x-z
key: 30-2.3 value: y-x-z …
Run Code Online (Sandbox Code Playgroud)

json hashtable hashmap

11
推荐指数
1
解决办法
293
查看次数

Razor MVC4 Url.Action无效

我在剃刀视图中有如下代码

<a href="@Url.Action("Details", "Mycontr", new {id =16}, Request.Url.Scheme)">
Run Code Online (Sandbox Code Playgroud)

当我双击这个项目时,它被重定向到Url下面

http://localhost:49280/Mycontr/Section/@Url.Action(
Run Code Online (Sandbox Code Playgroud)

但是预期的却是

http://localhost:49280/Mycontr/Details/16
Run Code Online (Sandbox Code Playgroud)

以下是RouteConfig

routes.MapRoute(
   name: "Capsule",
   url: "Mycontr/Details/{id}",
   defaults: new { controller = "Mycontr", action = "Details", id = UrlParameter.Optional }
 );
 routes.MapRoute(
   name: "Section",
   url: "Mycontr/Section/{id}",
   defaults: new { controller = "Mycontr", action = "Section", id = UrlParameter.Optional }
 );
Run Code Online (Sandbox Code Playgroud)

请建议.

我缩小了这个问题.Html.Raw导致问题.我有像这样的代码

@Html.Raw(HttpUtility.HtmlDecode(Model.sContent)) 
Run Code Online (Sandbox Code Playgroud)

该变量包含生成的具有Ur.Action的html.如果我只是直接将html生成的代码放在razor视图中而不使用Html.Raw它工作正常.但是,如果我拿出Html.Raw运行时生成的html脚本显示为

&lt;style type=&#39;text/css&#39;&gt;&lt;/style&gt;&lt;center&gt;&lt;div style=&quot;width:460px;&quot;&gt;&lt;div style=&quot;width: 460px; float: left;&quot;&gt;&lt;div s...
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以在不使用Html.Raw编码的情况下在变量中显示html脚本?通过使用HtmlString代替字符串变量来保存生成的Html脚本,解决了一半问题,但HtmlString无法解码字符串中的@ Url.Action语法.

以下是我一直在努力使其发挥作用的最新代码.请帮忙.

                string templFile = string.Format("{0}\\DivTemplate.htm", path);
            HtmlDocument divDoc = new HtmlDocument();
            StreamReader sRdr = new …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-routing url.action razor

7
推荐指数
1
解决办法
4万
查看次数

鼠标悬停在锚标签上不显示指针光标.在Chrome上观察到的行为,在IE 9上运行良好?

我的剃须刀视图中有一个代码,如下所示.鼠标悬停在任何锚标记上时,指针光标不显示.相同的代码在IE 9上运行正常.在Chrome浏览器上观察到此问题.有人猜测为什么以下代码在Chrome版本25.0.1364.172 m上失败了?

 <ul id="menu" class="menu">
                               <li><a href="#" style="cursor: pointer;">Top 10 Headlines</a>
                               </li>
                                <li><a href="#">Related Content</a>
                               </li>
                           </ul>
Run Code Online (Sandbox Code Playgroud)

anchor google-chrome cursor

3
推荐指数
2
解决办法
1万
查看次数

用特殊字符替换所有连续出现的字符

我填写空白表单,其中每个空白的长度不一致我想用特殊代码替换这些库以符合业务逻辑,下面是格式是如何

It is raining ________ in the forest   
The quick _______ dog jumps over ______________ fox
Run Code Online (Sandbox Code Playgroud)

我想重新格式化以上行,如下所示

It is raining [0] in the forest
The quick [0] dog jumps over [1] fox
Run Code Online (Sandbox Code Playgroud)

如上所述,每个空白的字符长度不一致,保持该情况想要在c#中使用正则表达式或不使用正则表达式编写可维护代码

例外

有些条目没有任何空格,在这种情况下应该按原样返回整个段落

蒂姆建议的代码很好,我的代码与蒂姆的答案如下.希望可以帮助别人

    Dictionary<string, string> dctE = new Dictionary<string, string>();
    Dictionary<string, string> dctT = new Dictionary<string, string>();
    string jsonT = string.Empty, jsonH = string.Empty;
    try
    {
        using (StreamReader r = new StreamReader(@"C:\samples\testmongo\testmongo\tamil1.txt"))
        {
            string langs = r.ReadToEnd();
            var lines = langs.Split('\n');
            for (int i = 1; i …
Run Code Online (Sandbox Code Playgroud)

c#

3
推荐指数
1
解决办法
60
查看次数