我创建了一个控制台应用程序和一个app.config文件以及Connections.config文件.app.config文件有一个指向Connections.config的connectionstring属性源
当我尝试读取应用程序中的连接字符串时,我得到了一个 ConfigurationErrorException
这是我的主要方法.
static void Main(string[] args)
{
var settings = ConfigurationManager.ConnectionStrings;
if (settings != null)
{
foreach (ConnectionStringSettings setting in settings)
{
Console.WriteLine(setting.ConnectionString);
}
}
}
Run Code Online (Sandbox Code Playgroud)
App.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings configSource="Connections.config"></connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
Connections.config文件
<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="SQLDBConnecion"
providerName="System.Data.ProviderName"
connectionString="" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我在这里观察了两件事.第一:如果我指定configSource,我无法读取连接字符串(抛出异常.)
第二:如果我在App.config文件中放入相同的连接字符串并尝试读取然后代码正在工作但获取两个连接字符串(应该只返回一个空字符串)第一个连接字符串是sqlexpress连接字符串,如下所示
data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
Run Code Online (Sandbox Code Playgroud)
它返回的第二个连接字符串是空字符串(这是预期的).
我想从我的场景中读取外部文件中的连接字符串.怎么做?我在这里错过了什么?
c# connection-string app-config external configuration-files
我试图修剪我从剑道编辑器得到的文本.
var html = " T "; // This sample text I get from Kendo editor
console.log("Actual :" + html + ":");
var text = "";
try {
// html decode
var editorData = $('<div/>').html(html).text();
text = editorData.trim();
console.log("After trim :" + text + ":");
}
catch (e) {
console.log("exception");
text = html;
}
Run Code Online (Sandbox Code Playgroud)
此代码位于单独的js文件中(从typescript生成).当页面加载时,修剪不起作用.但是,当我在开发人员工具控制台窗口中运行相同的代码时,它的工 为什么不工作?
添加打字稿代码
const html: string = $(selector).data("kendoEditor").value();
console.log("Actual :" + html + ":");
let text: string = "";
try {
// html decode
var editorData …
Run Code Online (Sandbox Code Playgroud) 我正在使用这个正则表达式来匹配 8 位有符号浮点数。
string exp= "12345678";
string regEx1="^([-+]?[(\\d+\\.?(\\d+)?)]{1,8})($)";
Regex topRowRegx = new Regex(regEx1, RegexOptions.IgnoreCase | RegexOptions.Multiline);
Match matchResult = topRowRegx.Match(exp.Trim());
Run Code Online (Sandbox Code Playgroud)
不管 -/+ 和 . 符号它应该匹配 1 到 8 位数字。
它应该匹配-1.2345678, 123.45678, +12.34, 1.2, 1, 12345678, 1254。如果有十进制符号,小数点前和小数点后至少应有一位。
上面的表达式工作正常,但是当我使用 -/+ 或 . 带有 8 位数字。你能帮我如何准确识别 8 位数字并留下剩余的符号数吗?
更新: Vasili Syrakis 的回答解决了上述问题。只是出于好奇,为什么这没有给出正确的结果?
string exp = "text> -9.9999999 \"some text here\"";
var resultNumber = Regex.Match(exp, "[-+]?(\\d{1,8}|(?=\\d\\d*\\.\\d+?$)[\\d\\.]{1,9})");
("Result:"+resultNumber.ToString()).Dump();
Run Code Online (Sandbox Code Playgroud) 我有这样的实体
class Test
{
string Name;
IList<SubTest> subTest;
}
class SubTest
{
string Id;
string value;
}
Run Code Online (Sandbox Code Playgroud)
从服务器我会得到的结果IEnumerable<Test>
.我想要将此结果转换为SelectListItem,以便我可以将其绑定到mvc下拉列表.
像这样的东西
new SelectListItem(){Group=Test.Name, Value=SubTest.Id, Text= subTest.Value}
Run Code Online (Sandbox Code Playgroud)
如何使用linq获得此结果?
我需要使用bat文件将源文件复制到目标文件夹。
我创建了这个:
@echo off
set source="D:\Folder1\file.dll"
set destination="D:\Test\TestCopy*\Test\"
xcopy /s /y %source% %destination%
pause
Run Code Online (Sandbox Code Playgroud)
我的目标路径是TestCopy.2.5.3.6
。这个数字可以改变。所以指定TestCopy*
不起作用。指定TestCopy.*.*.*.*
也不起作用。
我该如何解决?
该代码可以正常工作
Dictionary<string, bool> test = new Dictionary<string, bool>();
test.Add("test string", true);
Run Code Online (Sandbox Code Playgroud)
以下代码引发此错误:无法将类型“ void”隐式转换为“ System.Collections.Generic.Dictionary”
Dictionary<string, bool> test = new Dictionary<string, bool>().Add("test string", true);
Run Code Online (Sandbox Code Playgroud)
为什么?有什么不同?
c# ×3
app-config ×1
asp.net-mvc ×1
batch-file ×1
c#-4.0 ×1
dictionary ×1
external ×1
generics ×1
git ×1
javascript ×1
jquery ×1
kendo-editor ×1
linq ×1
linqpad ×1
regex ×1
trim ×1
xcopy ×1