Tag: string

运算符’==’不能应用于’int’和’string类型的操作数

我正在写一个程序,我想到一个数字,计算机猜测它。 我正在尝试测试它,但我一直都会遇到错误。 错误是主题标题。 我使用Int.Parse转换我的字符串,但我不知道为什么我收到错误。 我知道它说’==’不能和整数一起使用,但是我在网上看到的所有内容以及我class上的幻灯片都使用它,所以我被卡住了。 代码是不完整的,我不想让它运行,我只是想解决问题。 非常感谢任何帮助,谢谢:D class Program { static void Main(string[] args) { Console.Write(“Enter any number after 5 to start: “); int answer = int.Parse(Console.ReadLine()); { Console.WriteLine(“is it 3?”); if (answer == “higher”)

C#超大字符串操作(内存不足)

我需要从磁盘读取1gb原始文本文件到ram以在C#中进行一些字符串操作。 string contents = File.ReadAllText(path) 抛出内存exception(不出所料) 最好的方法是什么?

将整数值解析为日期时间

我的日期表示为整数,如20140820 ,我想将其解析为日期时间,如2014.08.20。 我是否需要使用索引解析每个整数值(2014)(08)(02)还是更简单的方法?

在.NET中发出字符串格式为“M”的DateTime.ToString

我有DateTime的字符串格式的问题。 我认为这是MS中的错误。 你能解释一下,有什么不对吗? class Program { static void Main(string[] args) { Console.WriteLine(DateTime.Now.ToString(“M”));//return 07 July <—- WRONG, SEE MSDN Console.WriteLine(DateTime.Now.ToString(".M"));//return .7 <—- GOOD Console.ReadKey(); } } MSDN

如何将两个字符串(日期和时间)组合到单个DateTime

我有两个字符串: string one = “13/02/09”; string two = “2:35:10 PM”; 我想将这两者结合在一起并转换为DateTime 。 我尝试了以下但它不起作用: DateTime dt = Convert.ToDateTime(one + ” ” + two); DateTime dt1 = DateTime.ParseExact(one + ” ” + two, “dd/MM/yy HH:mm:ss tt”, CultureInfo.InvariantCulture); 我能做些什么来完成这项工作?

Json:如何使用json.net正确剥离转义字符

我有以下格式的json响应。 “[{\\\”JobID\\\”:\\\”1\\\”,\\\”BillGenerationDate\\\”:\\\”4/29/2013 2:53:34 PM\\\”,\\\”BillID\\\”:\\\”115743\\\”,\\\”BillNo\\\”:\\\”115743\\\”,\\\”CustomerID\\\”:\\\”4041705\\\”,\\\”PayStatus\\\”:\\\”0\\\”,\\\”PaymentRequiredStatus\\\”:\\\”True\\\”,\\\”ProductName\\\”:\\\”Epic FBO test\\\”,\\\”Description\\\”:\\\”Epic Automation 2\\\\r\\\\n\\\”,\\\”ProductType\\\”:\\\”eBill \\\”,\\\”DueType\\\”:\\\”-1\\\”,\\\”DueDate\\\”:\\\”2013-03-15\\\”,\\\”Amount\\\”:\\\”63.70\\\”,\\\”Cost\\\”:\\\”\\\”}, {\\\”JobID\\\”:\\\”9\\\”,\\\”BillGenerationDate\\\”:\\\”5/2/2013 10:21:39 AM\\\”,\\\”BillID\\\”:\\\”115743\\\”,\\\”BillNo\\\”:\\\”115743\\\”,\\\”CustomerID\\\”:\\\”4041705\\\”,\\\”PayStatus\\\”:\\\”0\\\”,\\\”PaymentRequiredStatus\\\”:\\\”True\\\”,\\\”ProductName\\\”:\\\”FBO Test Product\\\”,\\\”Description\\\”:\\\”FBO Product Test\\\”,\\\”ProductType\\\”:\\\”eBill \\\”,\\\”DueType\\\”:\\\”-1\\\”,\\\”DueDate\\\”:\\\”2013-05-01\\\”,\\\”Amount\\\”:\\\”150.70\\\”,\\\”Cost\\\”:\\\”\\\”}] 我相信json.net处理转义字符,我使用下面的代码将它反序列化为字典集合。 var billList = JsonConvert.DeserializeObject<List<Dictionary>>(contentCorrected); 但是这个json解析会抛出exception“无效的属性标识符:.Path'[0]’,第1行,第2位。” 我们可以通过操纵json响应字符串来解决这个问题吗?

将TM superScript添加到字符串

我需要在C#字符串的标题旁边添加TM(商标)上标符号。 无论如何可能会这样做? 谢谢!

如何以逐字字符串的forms逃脱?

我对c#有点新,我在这一点上卡住了,我有一个常规的字符串,我在那里使用\来逃避” ,逃避这里意味着逃避编译器解释” ,并得到”印在屏幕,我得到预期的输出 – > class Program { static void Main(string[] args) { string s1 = “This is a \”regular\” string”; System.Console.WriteLine(s1); System.Console.Read(); } } o / p – >这是一个“常规”字符串 现在,我有一个逐字字符串,我试图逃避”以与上面相同的方式使用\ ..–> class Program { static void Main(string[] args) { string s2 = @”This is \ta \”verbatim\” string”;//this would escape \t System.Console.WriteLine(s2); System.Console.Read(); } } […]

字符串生成器与列表

我正在阅读包含数百万行的多个文件,并且我正在创建具有特定问题的所有行号的列表。 例如,如果特定字段留空或包含无效值。 所以我的问题是跟踪可能超过一百万行的数字列表最有效的日期类型。 使用String Builder,Lists或其他更有效的方法吗? 我的最终目标是输出一条消息,如“特定字段在1-32,40,45,47,49-51等处是空白的。所以在String Builder的情况下,我会检查以前的值,如果它是只有一个我会改变它从1到1-2如果它是多于一个将它用逗号分隔。使用List,我只是将每个数字添加到列表然后组合然后文件有已完全阅读。但在这种情况下,我可以有多个包含数百万个数字的列表。 这是我用于使用String Builder组合数字列表的当前代码: string currentLine = sbCurrentLineNumbers.ToString(); string currentLineSub; StringBuilder subCurrentLine = new StringBuilder(); StringBuilder subCurrentLineSub = new StringBuilder(); int indexLastSpace = currentLine.LastIndexOf(‘ ‘); int indexLastDash = currentLine.LastIndexOf(‘-‘); int currentStringInt = 0; if (sbCurrentLineNumbers.Length == 0) { sbCurrentLineNumbers.Append(lineCount); } else if (indexLastSpace == -1 && indexLastDash == -1) { […]

迭代的努力–FizzBu​​zz

编辑它的价值,承认可能不是那么多。 我做了一点测试来扩展这个问题。 我写了两个函数来枚举FizzBu​​zz“系列”。 private static IEnumerable SimpleFizzBuzz( int start = 0, int end = int.MaxValue) { return Enumerable.Range(start, end).Select(i => i % 15 == 0 ? “fizzbuzz” : i % 3 == 0 ? “fizz” : i % 5 == 0 ? “buzz” : i.ToString(CultureInfo.InvariantCulture)); } 和, private static IEnumerable OptimizedFizzBuzz( int start = 0, […]