计算文本文件中出现的特殊字符数。 [英] calculating the number of Special Characters occurrence in a text file.

查看:78
本文介绍了计算文本文件中出现的特殊字符数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 在计算文本文件中的  特殊字符出现时遇到问题。 < g class =" gr_ gr_60 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace"数据-GR-ID =" 60" ID = QUOT; 60 QUOT;> snerio< / g取代;
是"在WPF的文本框中加载文件,而不是显示文件内容,计算后在文本框中显示 
特殊字符的数量。并将此结果保存在< g class =" gr_ gr_160 gr-alert gr_gramm gr_inline_cards
gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep"数据-GR-ID =" 160" ID = QUOT; 160">文字< / g取代;文件。结果必须如下所示
"

 am facing a problem in counting the Special Characters occurrences in a text file. the <g class="gr_ gr_60 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="60" id="60">snerio</g> is " load a file in the textbox in WPF and instead of showing the file content, show the number of Special Characters in the textbox after calculation.and save this result in <g class="gr_ gr_160 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="160" id="160">text</g> file. the result must look like below"

Number of。(句号):232

Number of - (破折号码):232

Number of -( dash) :232

推荐答案

这是尝试的东西,用读取的信息替换项目var来自文本文件。

Here is something to try, replace items var with information read in from the text file.

string items = "ÝABCÓDE?ÃFGHÃI?YJKLÓƒƒMÆNOPRSŠTU??VZݽ¥¥¥¥";

Encoding iso = Encoding.GetEncoding("ISO-8859-1");
Encoding utf8 = Encoding.UTF7;
byte[] utfBytes = utf8.GetBytes(items);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
string itemsTranslated = iso.GetString(isoBytes);

var characterGroup = (
    from chr in itemsTranslated.ToCharArray()
    group chr by chr into grp
    select new
    {
        Letter = grp.Key,
        Occurrences = grp.Count(),
        Code = Convert.ToInt32((int)grp.Key)
    })
    .ToList()
    .OrderBy((item) => item.Letter.ToString());

var results = (from item in characterGroup select item);


foreach (var item in results)
{
    Console.WriteLine(


" {item.Letter} ,{item.Code},{item.Occurrences}");
}
"{item.Letter}, {item.Code}, {item.Occurrences}"); }

控制台写信的结果

, 4, 1
, 14, 1
, 15, 2
, 20, 1
?, 63, 4
¥, 165, 4
½, 189, 1
A, 65, 1
Ã, 195, 2
Æ, 198, 1
B, 66, 1
C, 67, 1
D, 68, 1
E, 69, 1
f, 102, 2
F, 70, 1
G, 71, 1
H, 72, 1
I, 73, 1
J, 74, 1
K, 75, 1
L, 76, 1
M, 77, 1
N, 78, 1
O, 79, 1
Ó, 211, 2
P, 80, 1
R, 82, 1
S, 83, 2
T, 84, 1
U, 85, 1
V, 86, 1
Y, 89, 1
Ý, 221, 2
Z, 90, 1


这篇关于计算文本文件中出现的特殊字符数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆