小编Jam*_*son的帖子

strtol的基础知识?

我真的很困惑.我必须遗漏一些相当简单的东西,但我读到的关于strtol()的任何内容都没有意义.有人能以一种非常基本的方式为我拼出它,并举例说明我可能会得到类似下面的东西吗?

string input = getUserInput;
int numberinput = strtol(input,?,?);
Run Code Online (Sandbox Code Playgroud)

c++ string int strtol

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

字符串未正确拆分

我试图将一个字符串拆分成一个字符串[],该字符串由最初使用该代码保存的字符串组成.

    private string[] ConvertWordsFromFile(String NewFileText)
    {
        char[] delimiterChars = { ' ', ',', '.', ':', '/', '|', '<' , '>','/','@','#','$','%','^','&','*','"','(',')',';'};       
        string[] words = NewFileText.Split(delimiterChars);
        return words;


    }
Run Code Online (Sandbox Code Playgroud)

然后我使用它将单词添加到字典中,以跟上单词键及其频率值.所有其他重复的单词不会作为键添加,只会影响该值.但是,最后一个单词被视为一个不同的单词,因此被制作成新的密钥.我怎样才能解决这个问题?

这是我在字典中添加单词的代码:

public void AddWord(String newWord)
    {
       newWord = newWord.ToLower();
        try
        {
            MyWords.Add(newWord, 1);
        }
        catch (ArgumentException)
        {
            MyWords[newWord]++;
        }

    }
Run Code Online (Sandbox Code Playgroud)

澄清我遇到的问题是,即使字符串末尾的单词是重复的,它仍然被视为一个新单词,因此是一个新字符串.

c# arrays string dictionary split

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

标签 统计

string ×2

arrays ×1

c# ×1

c++ ×1

dictionary ×1

int ×1

split ×1

strtol ×1