如果在javascript中有一个数组,如:
[[2,3,4],"data","payload",[name1,name2,name3]]
Run Code Online (Sandbox Code Playgroud)
我应该如何将所有值作为单个数组来获取
结果数组应该是这样的:
[2,3,4,"data","payload",name1,name2,name3]
Run Code Online (Sandbox Code Playgroud) 我试图通过在文本框中输入消息来在画布上显示文本,但它没有出现。
这是我的代码:
<html>
<body>
<canvas id="myCanvas" width="600" height="400"></canvas>
<input type="text" name="fname" size="50" id="form_val">
<button onclick="clicked()">Submit</button>
<script type="text/javascript">
function clicked () {
var x = document.getElementById("form_val");
return x.value;
}
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "25px Verdana";
ctx.fillText(clicked(), 250, 250);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 所以,我下载了Ubuntu并通过虚拟机运行它,期望(希望)我将运行Linux.键入后uname -a,我认为一切都很好(第一次输出),但是当我开始做一些密码时,它说输入新的UNIX密码(第二个输出).这是否意味着我正在运行UNIX或者这无关紧要?基于这两个输出,有人可以告诉我,我是在运行UNIX还是Linux?(我正在使用Mac,因此可能会影响它说输入新的UNIX密码的事实.我不认为它应该是因为我在虚拟机上运行终端.)
trevor@trevor-VirtualBox:/$ uname -a
Linux trevor-VirtualBox 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC
2014 x86_64 x86_64 x86_64 GNU/Linux
Enter new UNIX password:
Retype new UNIX password:
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Linq来确定字符串是否不在数组中.我正在使用的代码是:
if (!stringArray.Any(soughtString.Contains)){
doStuff();}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.显然创建一个foreach循环就足够了,但我想了解为什么这条线不起作用.是的,该文件有using System.Linq;
我发现C#的这个功能"命名参数"真的很奇怪,因为我看到了它的两个缺陷.该书说"命名参数赋予你"以任何顺序传递参数的能力".
我认为这个C#功能存在两个缺陷:
它违反了计算机科学中的"信息隐藏".(即:使用该方法的最终用户需要知道参数名称和数据类型才能使用该功能.)来自Java背景,这很奇怪.为什么要将参数名称暴露给用户的末尾?
它容易产生歧义,可能导致错误.(当程序员编写使用相同方法名称(也称为重载方法)的方法时,程序员需要进行额外的思考和问题.当你有两个同名的方法时,你总会得到一个"调用是不明确的"即使另一个方法具有不同数据类型的额外参数,彼此具有相同的参数.我能想到的唯一修复是使数据类型成为"强制参数",也就是没有默认值的参数,因此编译器会不要混淆.但是这个修复只是一个导致另一个最坏情况的绷带解决方案(见下文)
业内人士甚至在今天都使用这个概念吗?如果是这样,为什么要打破这两条规则"在调用方法时以任何顺序传递参数的能力"?
TLDR:通过引入可能的最坏情况场景(编译器选择了错误的方法调用......尽管两种方法相似)来清楚地说明我所说的内容:
namespace ConsoleApplication1
{
class Venusaur
{
static void Main(string[] args)
{
new Venusaur().optMethod(fourth: "s");
}
public void optMethod( string third , string fourth = "hello", int fifth = 23, string two = "w")
{
// what if I wanted this method to run instead of the method below me
Console.WriteLine("did not execute");
}
public void optMethod(string third = "Byte", string fourth = "hello", int fifth = 4)
{
// But this method ran instead …Run Code Online (Sandbox Code Playgroud) 所以我想找出a中特定括号之间的内容richtextbox.例如:
if (richTextBox1.Text.Contains("testname(") {
// Find what is in brackets of testname()
String outcome = //what is in brackets of testname()
}
Run Code Online (Sandbox Code Playgroud)
这可能很难理解,但让我们说这是richtextbox:
testname(name)
Run Code Online (Sandbox Code Playgroud)
然后字符串结果将是name.
我如何编写一个程序,输入一个由用户五位数组成的数字,将数字分成各自的数字,并打印出彼此分开的数字,每个数字各三个.例如,如果用户键入数字42339,则应打印该程序
4 2 3 3 9
Run Code Online (Sandbox Code Playgroud)