我的应用程序解析字符串数据,提取日期并确定日期格式并将其转换为yyyy-MM-dd.
源日期可以是任何石灰dd-mm-yyyy,dd/mm/yyyy,mm-dd-yyyy,mm/dd/yyyy或甚至yyyy-MM-dd.
除了使用开关盒尝试不同的排列和组合之外,还有其他有效的方法吗?
string sourceDate = "31-08-2012";
String.Format("{0:yyyy-MM-dd}", sourceDate);
Run Code Online (Sandbox Code Playgroud)
上面的代码只返回相同的sourceDate"31-08-2012".
我的对象层次结构如下:
class Detail
{
public List<Row> Rows { get; set; }
}
class Row
{
public List<Column> Columns { get; set; }
}
class Column
{
public string Name { get; set; }
public bool IsUpdated { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想设置column.IsUpdated = true其中column.Name ="id".我正在尝试这个,它不起作用.
detail.Rows.ForEach(r => r.Columns.Where(c => c.Name.ToLower().Equals("id")).ToList<Column>().Select(c => c.IsUpdated = true));
Run Code Online (Sandbox Code Playgroud) 例如,在以下类中,我需要Parent在Cupboard和中使用属性Shelf.我该怎么做?
public class Room
{
public List<Cupboard> Cupboards { get; set; }
}
public class Cupboard
{
public Room Parent
{
get
{
}
}
public List<Shelf> Shelves { get; set; }
}
public class Shelf
{
}
Run Code Online (Sandbox Code Playgroud) 我正在使用的xslt生成根上的所有标记.我需要得到<row>集合并<config>设置.
来源Xml:
<root>
<postdate>2011-03-30</postdate>
<location>84</location>
<meal>07:36</meal>
<config>
<postdate>2011-03-30</postdate>
<location>84</location>
<meal>07:36</meal>
<checknumber>91339082011-03-30T07:36:12</checknumber>
</config>
<items>
<row>
<descriptor>7297364</descriptor>
<qty>1</qty>
<price>33</price>
<value>33</value>
<recordtype>1</recordtype>
<postdate>2011-03-30</postdate>
<location>84</location>
</row>
<row>
<descriptor>7794473</descriptor>
<qty>1</qty>
<price>60</price>
<value>60</value>
<recordtype>1</recordtype>
<postdate>2011-03-30</postdate>
<location>84</location>
</row>
</items>
<tenders>
<row>
<id>13</id>
<value>117.99</value>
<recordtype>2</recordtype>
<postdate>2011-03-30</postdate>
<location>84</location>
</row>
</tenders>
<taxes>
<row>
<id>2</id>
<value>8.25</value>
<recordtype>3</recordtype>
<postdate>2011-03-30</postdate>
<location>84</location>
</row>
</taxes>
</root>
Run Code Online (Sandbox Code Playgroud)
尝试过Xslt:
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="row/*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
期望的输出:
<root>
<config>
<postdate>2011-03-30</postdate>
<location>84</location> …Run Code Online (Sandbox Code Playgroud) 由于其他原因重新安装 IIS 后,我现在无法使用“本地 IIS”选项在 Visual Studio 中调试 asp.net 应用程序。在重新安装 IIS 之前,一切正常。
这是我得到的错误。无法在 Web 服务器上开始调试。远程服务器返回错误:(404)未找到。`
我检查了 web.config,调试是真的
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)
检查 C:\Windows\System32\inetsrv\config 上的 applicationHost.config 请求过滤设置为允许。
<configSections>
<sectionGroup name="system.webServer">
<sectionGroup name="security">
<section name="requestFiltering" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
</configSections>
Run Code Online (Sandbox Code Playgroud)
我检查了调试器日志。不给任何线索。%UserProfile%\AppData\Local\Temp\Visual Studio Web Debugger.log 它显示
IIS 10.0 详细错误 - 404.6 - 未找到
以及一些html内容。这就是它提到请求过滤的地方,但这看起来不错。
我不确定是什么破坏了调试功能。
我究竟做错了什么?这是一个非常简单的陈述,但无法弄清楚是什么导致它失败
FMDatabase *db = [FMDatabase databaseWithPath:appDelegate.databasePath];
[db open];
isSuccess = [db executeUpdate:@"INSERT INTO notes (title, comment, fk) values (?, ?, ?);", title, comment, fkID];
Run Code Online (Sandbox Code Playgroud)
exception.name = NSInvalidArgumentException,exception.reason = - [__ NSCFString comment]:无法识别的选择器发送到实例0x68a93f
Note.h
#import <Foundation/Foundation.h>
@interface Note : NSObject
@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *comment;
@property (nonatomic) int fkID;
Run Code Online (Sandbox Code Playgroud) var employee =
{
Column1: null,
Column2: null,
create: function () {
var obj = new Object();
obj.Column1 = "";
obj.Column2 = "";
return obj;
}
};
Run Code Online (Sandbox Code Playgroud)
在C#中我会做这样的事情:
List<Employee> employees = new List<Employee>();
for (int i = 0; i < 10; i++)
{
Employee emp = new Employee()
{
Column1 = "column 1 of emp" + i;
Column2 = "column 2 of emp" + i;
}
employees.Add(emp);
}
Run Code Online (Sandbox Code Playgroud)
我需要在javascript中做同样的事情.
我在 Startup.cs 中有 SetPreFlightMaxAge。但 chrome“检查”>“网络”选项卡不会在响应标头中显示它。
启动.cs
app.UseCors(o =>
{
o.WithOrigins(allowedDomains.ToArray())
.SetPreFlightMaxAge(TimeSpan.FromMinutes(10))
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
});
Run Code Online (Sandbox Code Playgroud)
响应标头(GET 方法):除了一些其他标头之外,它还发送这些标头。下面第三行有一个 max-age,但这不是 Startup.cs 中设置的 10 分钟值
access-control-allow-credentials: true
access-control-allow-origin: ...
set-cookie: ...
strict-transport-security: max-age=2592000
vary: Origin,Accept-Encoding
Run Code Online (Sandbox Code Playgroud)
响应标头(OPTIONS 方法):
access-control-allow-credentials: true
access-control-allow-headers: ...
access-control-allow-origin: ...
set-cookie: ...
Run Code Online (Sandbox Code Playgroud) 我需要对所有列进行搜索,因此我不想在where子句中指定每个列名,而是创建一个可以搜索所有列的方法.
-(void) fillSomeobjectNames:(NSString *)filter
{
FMDatabase *db = [FMDatabase databaseWithPath:databasePath];
[db open];
NSString *sql = [NSString stringWithFormat:@"SELECT id, name, imagefile FROM %@ %@", mainTableName, filter];
FMResultSet *results = [db executeQuery:sql];
while([results next])
{
Someobject *someobject = [[Someobject alloc] init];
[someobject setID:[results intForColumn:@"id"]];
[someobject setName:[results stringForColumn:@"name"]];
NSString *iconName = [[results stringForColumn:@"imagefile"] stringByReplacingOccurrencesOfString:@".jpg" withString:@""];
[someobject setIconPath:[NSString stringWithFormat:@"%@-ico.jpg",iconName]];
[someobjects someobject];
}
[db close];
}
Run Code Online (Sandbox Code Playgroud)
'filter'可以是'WHERE remark = [searchText] AND description = [searchText]依此类推......
我试图得到一个独特的元素列表,但它总是返回一切.
XML:
<root>
<row>
<unit>CAN</unit>
</row>
<row>
<unit>KG</unit>
</row>
<row>
<unit>KG</unit>
</row>
<row>
<unit>PKT</unit>
</row>
<row>
<unit>CAN</unit>
</row>
<row>
<unit>PKT</unit>
</row>
<row>
<unit>KG</unit>
</row>
</root>
Run Code Online (Sandbox Code Playgroud)
LINQ:
List<XElement> elements = (from e in xdoc.Descendants("row").Elements()
where e.Name.Equals("unit")
select e).Distinct().ToList();
Run Code Online (Sandbox Code Playgroud)
预期输出:元素列表应包含3个项目
<unit>CAN</unit>
<unit>KG</unit>
<unit>PKT</unit>
Run Code Online (Sandbox Code Playgroud) c# ×3
asp.net ×1
asp.net-core ×1
fmdb ×1
iis ×1
javascript ×1
linq ×1
linq-to-xml ×1
objective-c ×1
parent ×1
properties ×1
webapi ×1
xslt-1.0 ×1