我正在尝试让Regex适合以下场景,但遇到一些麻烦.以下是场景.
我的字符串看起来像这样:
"The office timing (h) is from 8h to 18h."
从上面的字符串我需要"8h"和"18h".
到目前为止,我已经这样做了"[0-9]*[h]".但这给了我"h","8h"而且"18h".
有专家的想法吗?
这可能有点像一个愚蠢的问题,但我似乎根本找不到任何关于这种行为的信息.
这是代码:
class Cars
{
public int year = 0;
public string make = " ";
public string model = " ";
public Cars()
{
}
public Cars(int tYear, string tMake, string tModel)
{
year = tYear;
make = tMake;
model = tModel;
}
public string ConvertToString()
{
return year.ToString() + make + model;
}
}
class Program
{
Cars oneCar = new Cars();
List<Cars> manyCars = new List<Cars>();
public void Init()
{
manyCars.Add(new Cars(1993, "Nissan", "240SX"));
manyCars.Add(new Cars(2001, "Isuzu", …Run Code Online (Sandbox Code Playgroud) 我有一个界面
Public Interface IPlotSurface2D
WriteOnly Property PlotBackBrush() As IRectangleBrush
End Interface
Run Code Online (Sandbox Code Playgroud)
这是实现接口的类
Public Class PlotSurface2D
Implements IPlotSurface2D
Public WriteOnly Property PlotBackBrush() As IRectangleBrush _
Implements IPlotSurface2D.PlotBackBrush
Set(value As IRectangleBrush)
Me.plotBackBrush_ = DirectCast(value, IRectangleBrush)
Me.plotBackColor_ = DirectCast(Nothing, Object)
Me.plotBackImage_ = DirectCast(Nothing, Drawing.Bitmap)
End Set
End Property
End Class
Run Code Online (Sandbox Code Playgroud)
我收到以下编译错误:
错误 86“PlotBackBrush”无法通过类“PlotSurface2D”在项目外部公开类型“IRectangleBrush”。
我怎样才能解决这个问题?
目前,如果我这样做
decimal d;
temp = "22.00";
decimal.TryParse(temp, NumberStyles.Any, CultureInfo.InvariantCulture, out d);
Run Code Online (Sandbox Code Playgroud)
然后'd'变成22.有什么方法可以确保尾随的零没有被消灭掉?
仅供参考我正在使用.net 4.0
我有这行代码可以抛出null异常.
singleAddress.FullAddress = cc.MailingAddressStreet1.ToString() + " " +
cc.MailingAddressCity.ToString() + " " +
cc.MailingAddressState.ToString() + " " +
cc.MailingAddressZip.ToString() + " " +
cc.MailingAddressCountry.ToString();
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过添加if语句来检查它是否为null.但是有更好的推荐方法吗?
我只是想学习如何更好地处理这些异常(而不是编写超出我需要的代码).提前致谢.
所以当我的表单加载时,它将连接到数据库,当我点击按钮时,它会在我的数据库中插入一个新行,但是在我点击它后我没有看到我的表中的任何更改.
namespace database
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con;
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection();
con.ConnectionString =
"Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\myworkers.mdf;Integrated Security=True;User Instance=True";
con.Open();
MessageBox.Show("OPEN!");
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int x;
SqlCommand thiscommand = con.CreateCommand();
thiscommand.CommandText =
"INSERT INTO player_info (player_id, player_name) values (10, 'Alex') ";
x = thiscommand.ExecuteNonQuery(); /* I used variable x to verify …Run Code Online (Sandbox Code Playgroud) 我有一个问题,很容易计算一些简单的平均值.我的桌子:
id / user / action / data
1 / a / unit_price / 40
2 / a / quantity / 1
3 / b / unit_price / 70
4 / b / quantity / 2
Run Code Online (Sandbox Code Playgroud)
Unit_price是用户的价格,数量是数量.所以我应该得到:(40 + 70 + 70)/ 3 = 60
如果我做了
(AVG(action) WHERE action = unit_price)
我明白了:
(70+40)/2 = 55
如果我做了
(SUM(action) WHERE action = unit_price) / (SUM(action) WHERE action = quantity)
我明白了:
110 / 3 = 36.6
我找到的最简单的方法是不要将unit_price但全局价格放在PHP代码中进行划分以获得unit_price,但我希望SQL能为我做点什么.
假设夜间时间设定为20.30h至6.15h(AM).这两个参数是用户范围的变量.假设您的到达日期和出发日期可以从几分钟到一天以上.你如何计算夜晚的总小时数?
public static double CalculateTotalNightTimeHours(DateTime arrival,
DateTime departure,
int nightTimeStartHour,
int nightTimeStartMinute,
int nightTimeEndHour,
int nightTimeEndMinute)
{
//??
}
Run Code Online (Sandbox Code Playgroud)
编辑:我明白这可能不是直接的肯定/没有答案,但也许有人有一个优雅的解决方案来解决这个问题.回答评论:我确实想要计算用户可编辑的夜间开始和结束时间之间的总小时数(或分钟数).我正在计算访问时间,第一个日期确实是到达参数.
我的代码是:
DateTime nightStart = new DateTime( departure.Year, departure.Month, departure.Day,
nightTimeStartHour, nightTimeStartMinute, 0);
DateTime nightEnd = new DateTime( arrival.Year, arrival.Month, arrival.Day,
nightTimeEndHour, nightTimeEndMinute, 0);
if (arrival < nightEnd)
{
decimal totalHoursNight = (decimal)nightEnd.Subtract(arrival).TotalHours;
}
//...
Run Code Online (Sandbox Code Playgroud) 在我的SSIS包中使用的脚本下面.
If (Row.AnswerType.Trim().ToUpper = "MULTIPLE SELECT" And _
Row.SurveyQuestionID = Row.SurveyDefinitionDetailQuestionNumber) Then
Dim Question1 As String = Row.SurveyDefinitionDetailAnswerChoices.ToUpper.Trim()
Dim ans1 As String = Row.SurveyAnswer.ToUpper.Trim()
For Each x As String In ans1.Split(New [Char]() {CChar(vbTab)})
If Question1.Contains(x) Then
Row.IsSkipped = False
Else
Row.IsSkipped = True
'Row.IsAllowed = True
Row.ErrorDesc = "Invalid Value in Answer Column For Multiple Select!"
End If
Next
End If
Run Code Online (Sandbox Code Playgroud)
将选项卡作为分隔符时,此脚本只会成功.但我需要制表符和非制表符作为分隔符.
当我从 2010 年访问数据库中的本地表中删除 * 记录时,我没有任何问题,但是当我循环遍历列表并点击链接表(本地数据库,这是一个 fe/be 设置)时,它失败并显示:运行时错误' 3131': FROM 子句中存在语法错误。代码:
If sanityCheck2 = vbYes Then
DoCmd.SetWarnings False
'list the tables to purge here
dalist = "tblLocal1 tblRemote-2 tblRemote-3"
darray = Split(dalist, " ")
For i = LBound(darray) To UBound(darray)
DoCmd.OpenTable darray(i)
DoCmd.RunSQL squirrel
Next
DoCmd.SetWarnings True
Run Code Online (Sandbox Code Playgroud)
代码在 tblLocal1 上运行良好,但在任何遥控器上都不起作用。
我可以打开数据表中的表并删除记录,没有问题,只是不是通过这里。