【c# – 用.Substring一个字一个字地读取字符串?】教程文章相关的互联网学习教程文章

c# – 在Web Config中动态更改和切换connectionString的问题【代码】

我试图在运行时为Web应用程序切换不同的数据库. 塞纳里奥我们有一个asp.net Web应用程序和不同客户的不同数据库.我试图从一个公共数据库切换特定的连接字符串值,我保留连接字符串,特定客户ID和密码的映射表.成功的login后我正在从公共数据库中获取连接字符串,并通过在运行时替换选定的连接字符串来编辑web.config文件连接字符串部分.我这样做是通过添加以下代码登录事件conectionString = cString;Configuration openWebConfigurat...

c# – ConfigurationManager.ConnectionStrings.Add【代码】

我的想法在这里很难看 – 在ConfigurationManager.ConnectionStrings上有一个Add方法但是,如果我使用它,它会抛出“只读”错误消息.我对该问题的研究表明,我们无法在运行时以编程方式将连接字符串添加到app.config中.有一种解决方法,使用反射将ReadOnly标志设置为false 这是反射的例子:public static void AddConnectionString(SqlConnectionStringBuilder connectionString,string Name){try{typeof(ConfigurationElementCollecti...

c# – 从System.Runtime.dll而不是从mscorlib获取对System.String的引用

我有一个使用Assembly.ReflectionOnlyLoad的System.Runtime.dll的引用.当我在其上调用.GetType(“System.String”)时,我在mscorlib中获取System.String类型,而不是System.Runtime中的那个,这将导致我出现问题,因为我将生成错误的IL.有没有其他方法可以做到这一点?解决方法:你看到的是装配统一的结果.当您使用System.Reflection API发出程序集时,没有简单的方法可以避免将环境中的元数据(例如Type)引用泄漏到生成的程序集中.这是因...

c# – 在客户端上使用lz-string.js编码的.NET服务器上压缩/解压缩字符串

我使用lz-string.js的LZString.compressToBase64函数,需要解压缩/压缩服务器端的数据. 显而易见的解决方案似乎是lz_string_csharp,但我很担心 这个说法:If you use just the regular Javascript ‘compress’ function then depending on the data in the string, it will not decompress correctly on the C# side. However, if you are using the ‘compress’ function built into this C# version, then you should be ok to ...

C#string to number,当Parse失败时,TryParse返回true【代码】

我的数据库(SQL Server)中有一列将平均值存储为varchar. 值并不总是有效数字,它可以是:0,12,5.5,.4,4.0,6.,5.21428571428571428571428571428571428571,X,失败或只是空文本. 使用linq分配变量时,我想显示: >如果平均值是有效数字且> = 4则成功>如果平均值是有效数字且< 4>如果平均值不是有效数字,则为原始文本 代码 :myresults = myDataContext.myDbFunction() double note; from a in myresults select new MainReportModel() {...

c# – Asp.Net Core 2.0 ArgumentNullException:值不能为null.参数名称:connectionString【代码】

我在我的电脑上使用ASP.NET Core 2.0,Visual Studio 2017 Enterprise,版本15.5.4和本地数据库. 我是第一次使用数据库,我遇到了以下问题:unhandled exception occurred while processing the request.ArgumentNullException: Value cannot be null.Parameter name: connectionString. 在阅读并尝试每一个可能的建议以及可能的解决方案之后,问public class Startup {public Startup(IConfiguration configuration){Configuration = ...

c# – 我可以覆盖公共API中的类的ToString()吗?【代码】

我正在编写一个与另一个软件的API接口的工具.我的部分工具需要生成有关通过API找到的各种对象的报告,我希望这些报告包含标识每个对象的简单字符串.默认情况下,我计划使用ToString()为每个对象生成字符串.但是,毫不奇怪,我发现此API中的默认ToString()实现不具有描述性. 最初我想用一个很长的Switch语句做类似下面代码的事情.虽然这很可能会变得难以管理.public string GetAPIObjectDescrition(object obj) {Type t = obj.GetType()...

c# – StringTemplate中的回调或简单算术【代码】

我想在StringTemplate中使用类似的东西 – 调用在执行渲染的应用程序中定义的函数,这可能吗?<div> $renderArticle(article,width,padding)$</div> 我可以使用一个自定义类型/类只是为了这个领域,但这似乎有点被攻击,而不是问题的真正解决方案,并且它不会允许我传递参数据我所知. 我希望这是因为我想允许用户自定义模板,例如:我知道我可以为文章提供多少宽度,但我希望用户能够指定填充,以便我可以在该模板中生成最佳图像缩略图. 或...

c# – “无法执行”类似于“在System.Decimal和System.String上”.【代码】

我在使用DataGridView搜索价格(十进制)时遇到问题,此代码适用于字符串类型,但在我尝试搜索价格时出现错误:“无法在System.Decimal和System.String上执行”Like“.这是代码:BindingSource bs = new BindingSource(); bs.DataSource = dataGridView1.DataSource; bs.Filter = "price like '%" + Convert.ToDecimal(textBox16.Text) + "%'"; dataGridView1.DataSource = bs;解决方法:您正在尝试使用decimal作为字符串,这就是您收到错...

c# – System.Net.WebClient在UploadString期间没有抛出错误到无效的url?【代码】

鉴于此代码,我预计会发生异常,但System.Net.WebClient.UploadString会将空字符串返回到结果中. 我显然忽略了什么,但是什么?using System.Net; using System.Text;[TestClass()] public class WebClientTests {[TestMethod()]public void WebClientUploadStringToInvalidUrlTest(){var webClient = new WebClient { Encoding = Encoding.UTF8 };var result = webClient.UploadString("{{foo-bar}}", "snafu");Assert.IsTrue(strin...

C# string.Join的用法【代码】

string.Join分为以下五类,用法都有讲解。 HashSet<string> hs = new HashSet<string>(); hs.Add("111"); hs.Add("222"); hs.Add("333"); var str = string.Join(",", hs); Console.WriteLine(str); #region // 摘要: // 串联集合的成员,其中在每个成员之间使用指定的分隔符。 // 参数: // separator: // 要用作分隔符的字符串。只有在 values 具有多个元素时,separator...

c# – IFormattable.ToString无法正常工作以进行十六进制格式化【代码】

在尝试格式化为十六进制时,String.Format和IFormattable.ToString(format,value)提供不同的结果.使用IFormattable.ToString时如何获得正确的结果(格式,值)string format = "0x{0:X4}"; Console.WriteLine(string.Format(format, 255)); //prints- 0x00FFIFormattable formattableValue = (IFormattable)255; Console.WriteLine(formattableValue.ToString(format, null)); //prints- 25x{5:X4}解决方法:格式化字符串的格式对于stri...

c# – 将int转换为string用于dropdownlistfor【代码】

我有一个年龄的int属性,以及可供选择的年龄的选择列表.检索数据进行编辑时,我在添加tostring()方法时遇到错误:Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.所以我的viewmodel看起来像:public int LowerAgeLimit { get; set; } public List<SelectListItem> Ages { get; set; }我的查询是正确检索数据,然后在视图中我试图将数...

c# – 附加信息:将值[string]转换为[enum]类型时出错【代码】

每当我尝试反序列化下面的json字符串时,我收到此错误: 错误:Additional information: Error converting value“invalid_request_error” to type ‘ErrorType’. Path ‘type’, line 2,position 33.Json字符串{"error": {"type": "invalid_request_error","message": "Invalid request (check that your POST content type is application/x-www-form-urlencoded). If you have any questions, we can help at https://support....

c# – Dapper:ConnectionString属性尚未初始化【代码】

我第一次和Dapper一起玩.看起来像一个非常方便的小工具.但我遇到了一个问题.在下面的小控制台应用程序中,第一个方法按预期运行.但是第二种方法返回此错误:An unhandled exception of type ‘System.InvalidOperationException’ occurred in System.Data.dllAdditional information: The ConnectionString property has not been initialized.我可以改变方法的顺序并得到相同的结果.它总是在第二次调用时得到错误.不知道我做错了什...

SUBSTRING - 相关标签