在 C# 中处理文件 IO 的空输出
Null output dealing with file IO in C#
private async void btnClickThis_Click(object sender, EventArgs e)
{
//using example code from: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog?view=windowsdesktop-6.0
//to open a file dialog box and allow selection
//variable declaration by section
//file processing
var fileContent = string.Empty;
var filePath = string.Empty;
//counting vowels and storing the word
int vowelMax = 0;
int vowelCount = 0;
String maxVowels = "";
//finding length and storing longest word
int length = 0;
int lengthMax = 0;
String maxLength = "";
//for storing first and last words alphabetically
String first = "";
String last = "";
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "c:\";
openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
//Read the contents of the file into a stream
var fileStream = openFileDialog.OpenFile();
using StreamWriter file = new("Stats.txt", append: true);
using (StreamReader reader = new StreamReader(fileStream))
{
do
{
//try catch in case file is null to begin with
try
{
//read one line at a time, converting it to lower case to start
fileContent = reader?.ReadLine()?.ToLower();
//split line into words, removing empty entries and separating by spaces
var words = fileContent?.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (words != null)
{
foreach (var word in words)
{
//if the string is null, immediately store word
//if word < first, store word as first
if (first == null || String.Compare(word, first) < 0)
{
first = word;
}
//if the string is null, immediately store word
//if word > last, store word as last
else if (last == null || String.Compare(word, last) > 0)
{
last = word;
}
//find length of current word
length = word.Length;
//if len is greater than current max len, store new max len word
if (length > lengthMax)
{
maxLength = word;
}
//iterate over each letter to check for vowels and total them up
for (int i = 0; i < length; i++)
{
if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u')
{
vowelCount++;
}
}
//if vowelCount is greater than max, store word as new max
if (vowelCount > vowelMax)
{
maxVowels = word;
}
await file.WriteLineAsync(word);
}
}
} catch (IOException error)
{
Console.WriteLine("IOException source: {0}", error.Source);
}
} while (fileContent != "");
//append file stats after processing is complete
await file.WriteLineAsync("First word(Alphabetically): " + first);
await file.WriteLineAsync("Last word(Alphabetically): " + last);
await file.WriteLineAsync("Longest word: " + maxLength);
await file.WriteLineAsync("Word with the most vowels: " + maxVowels);
}
}
}
MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
}
我现在已经查看所有内容太久了,看不出有什么不妥。我正在获取一个 100% 有数据的文件(并在没有任何数据的情况下使用 try catch 块),并处理其信息,然后将其吐回文本文件中。我没有得到任何输出,我觉得(由于我不得不使用多少次 ? 来消除空文件警告)我的错误存在于 fileContent = reader?.ReadLine()?.ToLower();
行或 var words = fileContent?.Split(' ', StringSplitOptions.RemoveEmptyEntries);
线。任何帮助将不胜感激
编辑:通过将 reader?.readLine()?.ToLower();
更改为 reader.readToEnd()
并分离 fileContent = fileContent.toLower()
.
来修复我的文件 IO 问题
现在遇到对同一个文件进行多次迭代的问题。当输入我的测试数据时(其中我只是使用全部大写的原始口袋妖怪列表),我得到了它迭代的每个单词的输出(我不确定我明确在哪里声明以单词形式输出每个单词),我得到了相同内容的多个输出。
这是我更新的代码:`private async void btnClickThis_Click(object sender, EventArgs e)
{
//使用示例代码来自:https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog?view=windowsdesktop-6.0
//打开文件对话框并允许选择
//variable declaration by section
//file processing
var fileContent = string.Empty;
var filePath = string.Empty;
//counting vowels and storing the word
int vowelMax = 0;
int vowelCount = 0;
String maxVowels = "";
//finding length and storing longest word
int length = 0;
int lengthMax = 0;
//for storing first and last words alphabetically
String first = "";
String last = "";
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "c:\";
openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
//Read the contents of the file into a stream
var fileStream = openFileDialog.OpenFile();
using StreamWriter file = new("Stats.txt", append: true);
using StreamWriter test = new("testoutput.txt", append: true);
using (StreamReader reader = new StreamReader(fileStream))
{
do
{
//try catch in case file is null to begin with
try
{
//read the file, converting it to lower case to start
fileContent = reader.ReadToEnd();
fileContent = fileContent.ToLower();
//split file into words, removing empty entries and separating by spaces and new lines
var words = fileContent.Split(' ', '\n');
await test.WriteLineAsync("words: " + words + "\n");
//get longest word of file
var maxLength = words.OrderByDescending(n => n.Length).First();
await file.WriteLineAsync("Longest word: " + maxLength + "\n");
if (words != null)
{
foreach (var word in words)
{
await test.WriteLineAsync("current word: " + word + "\n");
//if word < first, store word as first
if (String.Compare(word, first) < 0)
{
first = word;
}
//if word > last, store word as last
else if (String.Compare(word, last) > 0)
{
last = word;
}
//find length of current word
length = word.Length;
//if len is greater than current max len, store new max len word
if (length > lengthMax)
{
maxLength = word;
}
//iterate over each letter to check for vowels and total them up
vowelCount = 0;
for (int i = 0; i < length; i++)
{
if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u')
{
vowelCount++;
await test.WriteLineAsync(word[i] + "\n");
await test.WriteLineAsync(vowelCount + "\n");
//if vowelCount is greater than max, store word as new max
if (vowelCount > vowelMax)
{
vowelMax = vowelCount;
maxVowels = word;
}
}
}
//await file.WriteLineAsync(word);
}
}
} catch (IOException error)
{
Console.WriteLine("IOException source: {0}", error.Source);
}
} while (fileContent != "");
//append file stats after processing is complete
await file.WriteLineAsync("First word(Alphabetically): " + first + "\n");
await file.WriteLineAsync("Last word(Alphabetically): " + last + "\n");
await file.WriteLineAsync("Word with the most vowels: " + maxVowels + "\n");
}
}
}
MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
}`
这是我的文件输出,它应该是一个格式化的文本文件,不显示大写字母(检查),第一个和最后一个单词按字母顺序排列(最后一个有效,第一个无效),最长的单词(检查),和元音最多的单词(检查)。
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically):
Last word(Alphabetically): bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Longest word: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Word with the most vowels: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically):
Last word(Alphabetically): bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Longest word: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Word with the most vowels: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically):
Longest word: charmander
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: mew
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: mew
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: mew
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: nidoqueen
在这里您尝试找到第一个(最小)单词。
string first = "";
....
if (String.Compare(word, first) < 0)
{
first = word;
}
但是“”出现在所有字符串之前。所以比较总是错误的。做
string first = "";
....
if (String == "" || String.Compare(word, first) < 0)
{
first = word;
}
private async void btnClickThis_Click(object sender, EventArgs e)
{
//using example code from: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog?view=windowsdesktop-6.0
//to open a file dialog box and allow selection
//variable declaration by section
//file processing
var fileContent = string.Empty;
var filePath = string.Empty;
//counting vowels and storing the word
int vowelMax = 0;
int vowelCount = 0;
String maxVowels = "";
//finding length and storing longest word
int length = 0;
int lengthMax = 0;
String maxLength = "";
//for storing first and last words alphabetically
String first = "";
String last = "";
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "c:\";
openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
//Read the contents of the file into a stream
var fileStream = openFileDialog.OpenFile();
using StreamWriter file = new("Stats.txt", append: true);
using (StreamReader reader = new StreamReader(fileStream))
{
do
{
//try catch in case file is null to begin with
try
{
//read one line at a time, converting it to lower case to start
fileContent = reader?.ReadLine()?.ToLower();
//split line into words, removing empty entries and separating by spaces
var words = fileContent?.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (words != null)
{
foreach (var word in words)
{
//if the string is null, immediately store word
//if word < first, store word as first
if (first == null || String.Compare(word, first) < 0)
{
first = word;
}
//if the string is null, immediately store word
//if word > last, store word as last
else if (last == null || String.Compare(word, last) > 0)
{
last = word;
}
//find length of current word
length = word.Length;
//if len is greater than current max len, store new max len word
if (length > lengthMax)
{
maxLength = word;
}
//iterate over each letter to check for vowels and total them up
for (int i = 0; i < length; i++)
{
if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u')
{
vowelCount++;
}
}
//if vowelCount is greater than max, store word as new max
if (vowelCount > vowelMax)
{
maxVowels = word;
}
await file.WriteLineAsync(word);
}
}
} catch (IOException error)
{
Console.WriteLine("IOException source: {0}", error.Source);
}
} while (fileContent != "");
//append file stats after processing is complete
await file.WriteLineAsync("First word(Alphabetically): " + first);
await file.WriteLineAsync("Last word(Alphabetically): " + last);
await file.WriteLineAsync("Longest word: " + maxLength);
await file.WriteLineAsync("Word with the most vowels: " + maxVowels);
}
}
}
MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
}
我现在已经查看所有内容太久了,看不出有什么不妥。我正在获取一个 100% 有数据的文件(并在没有任何数据的情况下使用 try catch 块),并处理其信息,然后将其吐回文本文件中。我没有得到任何输出,我觉得(由于我不得不使用多少次 ? 来消除空文件警告)我的错误存在于 fileContent = reader?.ReadLine()?.ToLower();
行或 var words = fileContent?.Split(' ', StringSplitOptions.RemoveEmptyEntries);
线。任何帮助将不胜感激
编辑:通过将 reader?.readLine()?.ToLower();
更改为 reader.readToEnd()
并分离 fileContent = fileContent.toLower()
.
现在遇到对同一个文件进行多次迭代的问题。当输入我的测试数据时(其中我只是使用全部大写的原始口袋妖怪列表),我得到了它迭代的每个单词的输出(我不确定我明确在哪里声明以单词形式输出每个单词),我得到了相同内容的多个输出。
这是我更新的代码:`private async void btnClickThis_Click(object sender, EventArgs e) { //使用示例代码来自:https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog?view=windowsdesktop-6.0 //打开文件对话框并允许选择
//variable declaration by section
//file processing
var fileContent = string.Empty;
var filePath = string.Empty;
//counting vowels and storing the word
int vowelMax = 0;
int vowelCount = 0;
String maxVowels = "";
//finding length and storing longest word
int length = 0;
int lengthMax = 0;
//for storing first and last words alphabetically
String first = "";
String last = "";
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "c:\";
openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
//Read the contents of the file into a stream
var fileStream = openFileDialog.OpenFile();
using StreamWriter file = new("Stats.txt", append: true);
using StreamWriter test = new("testoutput.txt", append: true);
using (StreamReader reader = new StreamReader(fileStream))
{
do
{
//try catch in case file is null to begin with
try
{
//read the file, converting it to lower case to start
fileContent = reader.ReadToEnd();
fileContent = fileContent.ToLower();
//split file into words, removing empty entries and separating by spaces and new lines
var words = fileContent.Split(' ', '\n');
await test.WriteLineAsync("words: " + words + "\n");
//get longest word of file
var maxLength = words.OrderByDescending(n => n.Length).First();
await file.WriteLineAsync("Longest word: " + maxLength + "\n");
if (words != null)
{
foreach (var word in words)
{
await test.WriteLineAsync("current word: " + word + "\n");
//if word < first, store word as first
if (String.Compare(word, first) < 0)
{
first = word;
}
//if word > last, store word as last
else if (String.Compare(word, last) > 0)
{
last = word;
}
//find length of current word
length = word.Length;
//if len is greater than current max len, store new max len word
if (length > lengthMax)
{
maxLength = word;
}
//iterate over each letter to check for vowels and total them up
vowelCount = 0;
for (int i = 0; i < length; i++)
{
if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u')
{
vowelCount++;
await test.WriteLineAsync(word[i] + "\n");
await test.WriteLineAsync(vowelCount + "\n");
//if vowelCount is greater than max, store word as new max
if (vowelCount > vowelMax)
{
vowelMax = vowelCount;
maxVowels = word;
}
}
}
//await file.WriteLineAsync(word);
}
}
} catch (IOException error)
{
Console.WriteLine("IOException source: {0}", error.Source);
}
} while (fileContent != "");
//append file stats after processing is complete
await file.WriteLineAsync("First word(Alphabetically): " + first + "\n");
await file.WriteLineAsync("Last word(Alphabetically): " + last + "\n");
await file.WriteLineAsync("Word with the most vowels: " + maxVowels + "\n");
}
}
}
MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
}`
这是我的文件输出,它应该是一个格式化的文本文件,不显示大写字母(检查),第一个和最后一个单词按字母顺序排列(最后一个有效,第一个无效),最长的单词(检查),和元音最多的单词(检查)。
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically):
Last word(Alphabetically): bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Longest word: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Word with the most vowels: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically):
Last word(Alphabetically): bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Longest word: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Word with the most vowels: bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
First word(Alphabetically):
Longest word: charmander
bulbasaur
ivysaur
venusaur
charmander
charmeleon
charizard
squirtle
wartortle
blastoise
caterpie
metapod
butterfree
weedle
kakuna
beedrill
pidget
pidgeotto
pidgeot
rattata
raticate
spearow
fearow
ekans
arbok
pikachu
raichu
sandshrew
sandslash
nidoran
nidorina
nidoqueen
nidoran
nidorino
nidoking
clefairy
clefable
vulpix
ninetales
jigglypuff
wigglytuff
zubat
golbat
oddish
gloom
vileplume
paras
parasect
venonat
venomoth
diglett
dugtrio
meowth
persian
psyduck
golduck
mankey
primeape
growlithe
arcanine
poliwag
poliwhirl
poliwrath
abra
kadabra
alakazam
machop
machoke
machamp
bellsprout
weepinbell
victreebel
tentacool
tentacruel
geodude
graveler
golem
ponyta
rapidash
slowpoke
slowbro
magnemite
magneton
farfetch'd
doduo
dodrio
seel
dewgong
grimer
muk
shellder
cloyster
gastly
haunter
gengar
onix
drowzee
hypno
krabby
kingler
voltorb
electrode
exeggcute
exeggutor
cubone
marowak
hitmonlee
hitmonchan
lickitung
koffing
weezing
rhyhorn
rhydon
chansey
tangela
kangaskhan
horsea
seadra
goldeen
seaking
staryu
starmie
mrmime
scyther
jynx
electabuzz
magmar
pinsir
tauros
magikarp
gyarados
lapras
ditto
eevee
vaporeon
jolteon
flareon
porygon
omanyte
omastar
kabuto
kabutops
aerodactyl
snorlax
articuno
zapdos
moltres
dratini
dragonair
dragonite
mewtwo
mew
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels:
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: mew
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: mew
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: mew
Longest word: charmander
Longest word:
First word(Alphabetically):
Last word(Alphabetically): zubat
Word with the most vowels: nidoqueen
在这里您尝试找到第一个(最小)单词。
string first = "";
....
if (String.Compare(word, first) < 0)
{
first = word;
}
但是“”出现在所有字符串之前。所以比较总是错误的。做
string first = "";
....
if (String == "" || String.Compare(word, first) < 0)
{
first = word;
}