小编Ian*_*Ian的帖子

从<1> </ 1>中提取文本(HTML/XML-Like但带有数字标记)

所以我有一个包含尖括号的长字符串,我希望从中提取文本部分.

string exampleString = "<1>text1</1><27>text27</27><3>text3</3>";
Run Code Online (Sandbox Code Playgroud)

我希望能够得到这个

1 = "text1"
27 = "text27"
3 = "text3"
Run Code Online (Sandbox Code Playgroud)

我怎样才能轻松获得这个?我无法想出一个非黑客的方法来做到这一点.

谢谢.

c#

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

OpenText 与 ReadLines

我遇到了一个逐行读取文件的实现,如下所示:

using (StreamReader reader = File.OpenText(path))
while (!reader.EndOfStream)
{
    string line = reader.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

但就我个人而言,我会这样做:

foreach (string line in File.ReadLines(path))
{

}
Run Code Online (Sandbox Code Playgroud)

有什么理由选择其中之一吗?

c# file-io stream readline

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

如何完成特定活动并非所有活动

在我的Android应用程序中假设有几个活动,如果使用意图,我会去这样的其他活动

[活动A] - > [活动B] - > [活动C] - > [活动-D] - > [活动N]

现在,当我按下按钮时我在活动N上然后我想去活动B并且想要销毁活动C和活动D但活动A不应该销毁.我也在各种帖子中搜索,但我没有得到完全相同的解决方案.

o任何帮助都将得到满足

android android-intent

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

C# 输出到文本框

这听起来真的很愚蠢,但我正在上一门 C# 课程,在那里我们跳过这本书,只在控制台应用程序中工作。我们得到了一个练习,根据冠词、名词、动词和介词的数组在字符串中构建句子,并将字符串的第一个单词中的第一个字母大写。关键是,它希望输出到文本框。这不会是一个问题,除非

a) 我们跳过了所有关于 GUI 的章节(将在下一季度的 C# 课程中介绍),并且

b) 我查过这本书,甚至 Stack Overflow 和其他在线资源,但无法弄清楚。

不幸的是,我的老师昨晚选择不在课堂上讨论这个练习。因为他和我不在同一页上(不是不喜欢,更多的是化学反应),我试图自己解决这个问题。上交的最后期限已经过去,所以我现在只要求个人的启发。

所以,这是我创建的代码。我写它输出到控制台只是为了表明我有问题的基本机制。我知道我必须在 GUI 窗口中创建一个带有文本框的单独表单,但我不知道如何将输出发送到文本框而不是控制台。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace _16._4_StoryWriter
    {
       class StoryWriter
       {
          static void Main(string[] args)
          {
             string[] articles = { "the", "a", "one", "some", "any" };
             string[] nouns = { "boy", "girl", "dog", "town", "car" };
             string[] verbs = { "drove", "jumped", "ran", "walked", "skipped" };
             string[] preps = { "to", "from", "over", "under", "on" };

             string …
Run Code Online (Sandbox Code Playgroud)

c# textbox output

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

当文件被拒绝访问而对文件被拒绝时,File.Exists的行为会有所不同

基于对MSDN文档File.Exists,该File.Exists方法应该返回false的任何错误,包括没有获得主叫用户读取文件.

我希望它false在文件被设置为FullControl拒绝给用户时返回,并FullControl拒绝用户拒绝该文件所在的目录.

我所看到的是当用户访问目录而不是文件时,File.Exists返回true; 但是,如果用户无权访问该目录,则File.Exists返回false.

我写了一个小程序来演示我在说什么:

using System;
using System.DirectoryServices;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;

namespace ConsoleApplication1
{
    internal class Program
    {
        private const string DirName = "TestDir";
        private const string FileName = "File.txt";
        private const string Password = "Password1";
        private const string UserName = "PermissionTestUser";
        private static WindowsImpersonationContext Identity = null;
        private static IntPtr LogonToken …
Run Code Online (Sandbox Code Playgroud)

c# impersonation file-io file-exists

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

为什么这段代码在某些情况下会引发IndexError?

我的功能是这样的:

输入:

8
Run Code Online (Sandbox Code Playgroud)

输出:

['000', '001', '010', '011', '100', '101', '110', '111']
Run Code Online (Sandbox Code Playgroud)

所以这是创建一个列表来存储input_number从0开始的二进制数.这是我的代码(正确的版本):

import math

input_num = 8
max_bit = math.ceil(math.log(input_num, 2))

list_Bin = [None] * input_num

for i in range(input_num):
    extra_d = max_bit - len(bin(i)[2:])
    list_Bin[i] = '0'*extra_d + bin(i)[2:]

print(list_Bin)
Run Code Online (Sandbox Code Playgroud)

这段代码效果很好.但是,如果我改变一行代码:

list_Bin = [None] * input_num
Run Code Online (Sandbox Code Playgroud)

list_Bin = [] * input_num
Run Code Online (Sandbox Code Playgroud)

它会引发IndexError.

我真的很想知道为什么,因为我多次遇到过这个问题.

python indexing list python-3.x

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

C#将YYYY-MM-DD转换为MM/DD/YYYY(" - "TO"/")

嘿,我遇到了麻烦.

string record = el.InnerText;
var result1 = parseString(record);
var StartDate = string.Join("", result1.ConvertAll(r => string.Format("{0}", r)).ToArray());
//DateTime strStartDate = DateTime.ParseExact(StartDate, "mm-dd-yyyy", CultureInfo.InvariantCulture);
var EndDate = string.Join("", result1.ConvertAll(r => string.Format("{1}", r)).ToArray());
//DateTime strEndDate = DateTime.ParseExact(EndDate, "mm-dd-yyyy", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

这是parseString功能:

private static List<string[]> parseString(string input)
    {
        var pattern = @"Start\s+Date:\s+([0-9-]+)\s+End\s+Date:\s+([0-9-]+)\s+(?:Warranty\s+Type:\s+\w+\s+)?Status:\s+(\w+)\s*";
        return Regex.Matches(input, pattern).Cast<Match>().ToList().ConvertAll(m => new string[] { m.Groups[1].Value, m.Groups[2].Value, m.Groups[3].Value });
    }
Run Code Online (Sandbox Code Playgroud)

DateTimes不工作,因为我是" - "转换的时候是不是一个有效的字符stringDateTime.

我试过record = record.Replace("-", "/")但最终弄乱了我的字符串并且它停止显示(来自html页面).

c# datetime

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

将双值导出为CSV

我试图将double值导出到CSV文件,如下所示

double[] arr = new double[] { 0.0000074, 0.00000123, 0.0000001254 };
using (StreamWriter writer = new StreamWriter(@"D:\Test.csv"))
{
    foreach (double item in arr)
    {
        writer.WriteLine(item);
    }
};
Run Code Online (Sandbox Code Playgroud)

CSV打开时的输出是Excel/Notepad相同的,如下所示

7.40E-06
1.23E-06
1.25E-07
Run Code Online (Sandbox Code Playgroud)

期望输出与CSV文件中的输入相同.期待任何形式的意见/建议.谢谢.

c# csv double export-to-csv

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

Windows 上的本地 Mongo - 无法连接到服务器 127.0.0.1:27017,连接尝试失败

安装Mongo 3.2Windows 8.1. 明白啦:

c:\foo>"c:\Program Files\MongoDB\Server\3.2\bin\mongo.exe"
MongoDB shell version: 3.2.5
connecting to: test
2016-04-26T13:41:31.032+0100 W NETWORK  [thread1] Failed to connect to 127.0.0.1
:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2016-04-26T13:41:31.034+0100 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

c:\foo>ver

Microsoft Windows [Version 6.3.9600]
Run Code Online (Sandbox Code Playgroud)

为什么?

我还能说什么?

windows localhost mongodb windows-8 windows-8.1

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

如何在 ASP.Net MVC 5 中跟踪匿名用户的活动?

我创建了一个ASP.Net MVC 5Web 应用程序,其服务可供匿名用户使用。当匿名用户使用 Web 服务时,它会从数据库中进行一些查询。但是,出于安全原因,我的客户想要跟踪匿名用户的“可疑”活动。其中之一包括匿名用户每天查询的次数(以防止大量数据被“窃取”)。

有没有办法捕获这些信息?

对于注册用户,我们可以在被ApplicationUser调用者中创建额外的属性QueryNo并将其添加Claim如下:

public class ApplicationUser : IdentityUser {
    public uint QueryNo { get; set; } //how many times this user has queried

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        userIdentity.AddClaim(new Claim("QueryNo", QueryNo));
        return userIdentity;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我们想要跟踪它的活动时,我们可以简单地增加它的QueryNo每个查询活动。例如,当我们想要显示它时,我们可以简单地定义一个扩展,Identity如下所示:

public static class …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc user-activity asp.net-mvc-5

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