字符串长度应为6到20个字符.它应该包含1个大写字母.
我可以使用C#在代码中执行此操作:
string st = "SomeString"
Regex rg = new Regex("[A-Z]");
MatchCollection mc = rg.Matches(st);
Console.WriteLine("Total Capital Letters: " + mc.Count);
if (mc.Count > 1)
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
但我真正想要的是一个正则表达式,它将匹配我的字符串,如果它只包含一个大写字母.字符串可以以普通字母开头,并且只能包含字母.
我希望在我的项目中使用正则表达式模式进行验证.
以下是正则表达式的描述:
长度必须至少为8个字符.
必须包含至少1个大写字符.
必须包含至少1个小写字符.
必须至少包含1个数字.
可能包含以下字符:
"<> $〜'`!@#%^&*() - + {} [] =:,.?/ | \
不得使用重复字符.(aa,11等)
不得使用超过3个连续字符.(abcd,wxyz,1234等)
#include <iostream>
using namespace std;
int main() {
int n, a = 0xfffffff;
cin >> n;
while (n--) {
string s;
cin >> s;
int c = 0;
for (char ch : s)
c |= 1 << (ch - 'a');
a &= c;
}
cout << __builtin_popcount(a) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该代码用于查找字符是否存在于所有输入的字符串中至少一次.有人可以解释这段代码中发生的事情.我试图在C++中学习一些明智的操作,但我无法理解这里发生了什么.
我可以同时使用工具和扩展吗?因为我需要在同一个类上使用工具时继承其他类的东西.
public class DetailActivity extends AppCompatActivity
implementsView.OnClickListener "extends ListActivity"
Run Code Online (Sandbox Code Playgroud)
怎么会这样?
是否可以以不同颜色显示格式化输出:
console.WriteLine(“First {0} second{1} ”, firstString, secondString)
Run Code Online (Sandbox Code Playgroud)
我想显示的变化而示出输出,就像firstString一种颜色和secondString在另一种颜色.
此代码适用于chrome.但是,它在IE中运行时不会打印日期值.任何人都可以回答,为什么这在IE中不起作用以及chrome如何解释'day'(tenDates [0] .day)作为关键.
<html>
<body>
<p id="demo"></p>
<script>
var tenDates = [];
day = "Monday";
date = "10/10/1976";
tenDates.push({
day, date
});
document.getElementById("demo").innerHTML =
tenDates[0].day
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我在以下代码中收到编译错误"并非所有代码路径返回值",为什么?!
public class SomeEntity
{
public int m_i;
public SomeEntity(int i)
{
m_i = i;
}
public override string ToString()
{
return m_i.ToString();
}
public static int someFunction(int i) { return i + 100; }
public static IEnumerable GetEntities()
{
int [] arr = {1,2,3};
foreach (int i in arr)
{
// for (int i = 0; i < someArray.Count();i++)
// yield return new SomeEntity(someFunction(i));
// *** Equivalent linq function ***
return Enumerable.Range(0, 7).Select(a => new SomeEntity(someFunction(a)));
}
}
} …
Run Code Online (Sandbox Code Playgroud) 是什么double.MaxValue
和double.MinValue
意味着在以下方面:
double minX, minY, maxX, maxY;
minX = double.MaxValue;
minY = double.MaxValue;
maxX = double.MinValue;
maxY = double.MinValue;
for(int i = 0 ; i < HPts.BranchCount; i++){
foreach(Point3d pt in HPts.Branch(i)){
if(minX > pt.X){
minX = pt.X;
}
if(minY > pt.Y){
minY = pt.Y;
}
if(maxX < pt.X){
maxX = pt.X;
}
if(maxY < pt.Y){
maxY = pt.Y;
}
Run Code Online (Sandbox Code Playgroud) 我有一个 JSON 文件:
{
"items": [
{
"id": "HkWO1yuYnLU",
"snippet": {
"channelId": "UCR5wZcXtOUka8jTA57flzMg",
"title": "?lyas Yalç?nta? - ?çimdeki Duman",
"categoryId": "10"
},
"statistics": {
"viewCount": "37266431",
"likeCount": "122255",
"dislikeCount": "4472",
"favoriteCount": "0",
"commentCount": "7151"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想得到这个信息,像这样:
label1.text = "Rap GOD"
label2.text = "122255 likes"
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我有以下代码:
static void Main(string[] args)
{
// Add 5 Employees to a Dictionary.
var Employees = new Dictionary<int, Employee>();
Employees.Add(1, new Employee(1, "John"));
Employees.Add(2, new Employee(2, "Henry"));
Employees.Add(3, new Employee(3, "Jason"));
Employees.Add(4, new Employee(4, "Ron"));
Employees.Add(5, new Employee(5, "Yan"));
}
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以像 Java 一样简单地打印字典的值?例如,我希望能够打印如下内容:
拥有密钥 1 的员工:Id=1,姓名= John
拥有密钥 2 的员工:Id=2,姓名= Henry
.. ETC..
谢谢。
抱歉,我习惯了Java!