小编jth*_*h41的帖子

为什么我的Javascript trim功能不起作用?

我正在使用这个功能来构建一个猪拉丁语翻译器,除了.trim()部分外,似乎已经找到了一切.我该怎么办?

function ParseText() 
{

  var  myText = "asdf\n hat\n cat dog\n apple";

  var lines = myText.split("\n");
  var results = "";

  for (var i = 0, len = lines.length; i < len; i++) {
    lines[i].trim();
    var words = lines[i].split(" ");

    for (var j = 0, lenght = words.length; j < lenght; j++) {
      var word = words[j];

      if (word.charAt(0) == "a" || word.charAt(0) == "e" ||  word.charAt(0) == "i" || word.charAt(0) == "o" || word.charAt(0) == "u" || word.charAt(0) …
Run Code Online (Sandbox Code Playgroud)

javascript whitespace trim removing-whitespace

5
推荐指数
1
解决办法
1万
查看次数

正确使用LINQ来洗牌

我正在尝试写一个简单的纸牌游戏.为了提出一个好的改组算法,我遇到了Jeff Atwood 关于Coding Horror 的帖子.

但是,当我在调用构造函数后查看对象的内容时,它们不会被洗牌.

以下是我尝试使用Jeff的解决方案:

class MainDeck : List<Card>
{
   public MainDeck()
    {
        this.Add(new Card(1, "Hearts"));
        this.Add(new Card(2, "Hearts"));
        this.Add(new Card(3, "Hearts"));
        ...

        this.OrderBy(a => Guid.NewGuid());
    }
}
Run Code Online (Sandbox Code Playgroud)

这是卡的代码:

class Card
    {
        string suit;
        int value;

        public Card(int value, string suit)
        {
            this.value = value;
            this.suit = suit;
        }

        bool isFaceCard()
        {
            if (value >= 11 || value == 1)
                return true;
            else
                return false;
        }

        public override string ToString()
        {
            return (value +", " + …
Run Code Online (Sandbox Code Playgroud)

c# linq list playing-cards

5
推荐指数
3
解决办法
1万
查看次数

使用Google Script发推文

我从这个问题中提取了这段代码.

应用作者的解决方案,我总是给出这个错误: 在此输入图像描述

我从我创建的Twitter应用程序中获取了我的密钥和秘密:

在此输入图像描述

我已将应用程序配置为编写...

我究竟做错了什么?

//post tweet
function oAuth() {
  var CONSUMER_KEY = "xxxx";
  var CONSUMER_SECRET = "xxxxx";
  ScriptProperties.setProperty("TWITTER_CONSUMER_KEY", CONSUMER_KEY);
  ScriptProperties.setProperty("TWITTER_CONSUMER_SECRET", CONSUMER_SECRET);
  var oauthConfig = UrlFetchApp.addOAuthService("twitter");
  oauthConfig.setAccessTokenUrl("https://api.twitter.com/oauth/access_token");
  oauthConfig.setRequestTokenUrl("https://api.twitter.com/oauth/request_token");
  oauthConfig.setAuthorizationUrl("https://api.twitter.com/oauth/authenticate");
  oauthConfig.setConsumerKey(ScriptProperties.getProperty("TWITTER_CONSUMER_KEY"));
  oauthConfig.setConsumerSecret(ScriptProperties.getProperty("TWITTER_CONSUMER_SECRET"));
  var options = {muteHttpExceptions: true,oAuthServiceName:'twitter',oAuthUseToken:'always'}
  var url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
  var response = UrlFetchApp.fetch(url, options).getContentText();
  Logger.log(response);
}
function postTweet() {
  oAuth();
  Logger.log('oAuth complete');
  var status='Operational!';
  var options = {
    "method": "post",
    "oAuthServiceName": "twitter",
    "oAuthUseToken": "always",
    "payload":{"status":status}
  };
  var url = "https://api.twitter.com/1.1/statuses/update.json";
  Logger.log('begin post');
  var request = UrlFetchApp.fetch(url, options); …
Run Code Online (Sandbox Code Playgroud)

twitter oauth google-apps-script

5
推荐指数
1
解决办法
264
查看次数

NUnit Test Runner和Visual Studio NUnit Test运行器为测试获得不同的结果

我写的几何库中,当我在Visual Studio中使用NUnit测试运行器运行时,我有一个奇怪的测试,但是当它在常规NUnit运行器上运行时,它会失败.我正在测试相同的DLL

这是测试:

    [Test()]
    public void Line_Sort()
    {
        Line line1 = new Line(PointGenerator.MakePointWithInches(3, 2, 5), PointGenerator.MakePointWithInches(5, 3, 7)); //intersects at -1, 0, 1
        Line line2 = new Line(PointGenerator.MakePointWithInches(6, 0, 0), PointGenerator.MakePointWithInches(-5, 3, -1)); //intersects at 6, 0, 0
        Line line3 = new Line(PointGenerator.MakePointWithInches(1, 1, 5), PointGenerator.MakePointWithInches(2, 2, 4)); //intersects at 0, 0, 6
        Line line4 = new Line(PointGenerator.MakePointWithInches(4, 10, 1), PointGenerator.MakePointWithInches(4, 5, 2)); //intersects at 4, 0, 3
        Line line5 = new Line(PointGenerator.MakePointWithInches(4, 2, 2), PointGenerator.MakePointWithInches(4, 2, 1)); …
Run Code Online (Sandbox Code Playgroud)

nunit unit-testing visual-studio

5
推荐指数
0
解决办法
165
查看次数

VB6语法问题,"没有当前记录"错误

我正在使用sql server 2005在vb6中编写应用程序.这是我当前的代码.

Dim Sqlstring As String
Dim rstCurrentTicket As Recordset

Sqlstring = "Select SubmiterName, LastViewDate, Department, Description, Urgency, SubmitDate, ResolvedDate from TroubleTickets where Title ='" + Trim(TicketComboBox.Text) + "'"
Set rstCurrentTicket = cnnSel.OpenRecordset(Sqlstring)


NameText.Text = rstCurrentTicket!SubmiterName
DeptText.Text = rstCurrentTicket!Department
Me.DescriptionText = rstCurrentTicket!Description
Me.UrgencyText = rstCurrentTicket!Urgency
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我收到一个错误代码说:

"运行时错误:'3021'""没有当前记录"

它强调了这一行代码:

NameText.Text = rstCurrentTicket!SubmiterName
Run Code Online (Sandbox Code Playgroud)

有关如何解决此问题的任何建议?

sql vb6 syntax ado recordset

4
推荐指数
1
解决办法
2351
查看次数

Excel工作簿输入上的奇怪错误

对于当前代码:

 String currentPath = Directory.GetCurrentDirectory();

        OpenFileDialog op = new OpenFileDialog();
        op.InitialDirectory = currentPath;
        if (op.ShowDialog() == DialogResult.OK)
            currentPath = op.FileName;
        else
        {
            toolStripStatusLabel1.Text = "Failed to Load Workbook";
            toolStripStatusLabel1.Visible = true;
        }

        Workbook wb = new Workbook(excel.Workbooks.Open(currentPath));
Run Code Online (Sandbox Code Playgroud)

我收到错误:

System.Runtime.InteropServices.COMException未处理Message =检索具有CLSID {00020819-0000-0000-C000-000000000046}的组件的COM类工厂因以下错误而失败:80040154类未注册(HRESULT异常:0x80040154(REGDB_E_CLASSNOTREG) )).Source = mscorlib ErrorCode = -2147221164

我想要的只是一个预定义的工作簿来添加工作表

c# excel visual-studio-2010 excel-interop

4
推荐指数
1
解决办法
1万
查看次数

随机密码生成器

我正在尝试编写一个随机密码生成器.我处于早期阶段,遇到了一些问题.使用下面的代码和屏幕截图,您可以看到我得到一个非常可预测的字符串(字符串为2).每次我收到一个只填充一种号码的字符串.我应该如何编辑代码以生成更好的密码字符串?(除了包括不仅仅是数字)

在此输入图像描述

private void button1_Click(object sender, EventArgs e)
{
    int characters = Convert.ToInt32(comboBox1.SelectedIndex);
    string password = "";

    for(int i = 0; i <= characters; i++)
    {
       password = password +charGen();
    }

    label2.Text = password;
}

private char charGen()
{
    Random random = new Random();
    char randomNumber = Convert.ToChar( random.Next(48, 57));
    return randomNumber;
}
Run Code Online (Sandbox Code Playgroud)

}

c# random passwords ascii winforms

4
推荐指数
1
解决办法
2911
查看次数

找不到对System.Diagnostics.Stopwatch的引用

我正在尝试构建一个简单的秒表WPF应用程序.

这是我的代码:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Diagnostics;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    public stopWatch = new Stopwatch();

    private void startTimer()
    {
        stopWatch.Start();
        Dispatcher.BeginInvoke(DispatcherPriority.Render, new ThreadStart(ShowElapsedTime));
    }
    void ShowElapsedTime()
    {
        TimeSpan ts = stopWatch.Elapsed;
        lblTime.Text = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

和这里

在此输入图像描述

我正在使用System.Diagnostics但由于某种原因我无法访问秒表

而且我在这个对话中找不到System.Diagnostics:

在此输入图像描述

为什么我不能使用System.Diagnostics.Stopwatch?为什么System.Diagnostics没有出现在引用对话框中?

.net c# wpf stopwatch visual-studio-2012

4
推荐指数
1
解决办法
4833
查看次数

强制Visual Studio调试工具显示有用的信息

众所周知,当你想在Visual Studio Debugger中查看复杂对象的内部变量时,你会得到类似这样的类名,你必须展开它才能看到公共属性:

在此输入图像描述

我试图使用这个问题的答案中的代码,而不是为每个类重写toString方法.

但它似乎没有任何区别.我还能尝试什么?

c# properties tostring typeconverter visual-studio-2013

4
推荐指数
1
解决办法
731
查看次数

如何序列化从字典派生的类

我正在尝试使用Json.Net将以下类与Json进行序列化/反序列化:

public class ChildDictionary:Dictionary<Employee, double>
{

    public string Name { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

我已经在这里这里这里找到了相关的信息,但是它们都没有专门处理从字典派生的这种情况下的语法。

员工自己成功地与Json.Net进行了序列化。看起来像这样:

[JsonObject(MemberSerialization.OptIn)]
public class Employee
{

    [JsonProperty]
    public string Name { get; set; }

    [JsonProperty]
    public double Factor { get; set; }

    [JsonProperty]
    public List<ILoadBuilder> LoadBuilders = new List<ILoadBuilder>();

    [JsonConstructor]
    public LoadCause(string name, double factor, List<ILoadBuilder> loadBuilders)
    {
        this.Name = name;
        this.DurationFactor = Factor;
        this.LoadBuilders = loadBuilders;
    }
}
Run Code Online (Sandbox Code Playgroud)

只要我可以在不丢失数据的情况下进行读写,我就不会在乎Json到底是什么样子

关于完成此操作的代码的任何建议应该看起来像什么?Custom JsonConverter或Attributes都是很好的解决方案。

c# serialization json dictionary json.net

4
推荐指数
1
解决办法
628
查看次数