C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,945 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need to find the position of the double quotation mark (") character in a text that contains several.
I read the text with this command:
StreamReader fileRead = File.OpenText (@filepath)
How can I do?
Thanks in advance
Marco Dell'Oca
Hello @Marco Dell'Oca ,
This is one idea to loop through lines in the file (assuming you are reading lines in a file)
var fileName = "TextFile1.txt";
if (!File.Exists(fileName))
{
return;
}
var counter = 0;
string line;
using (var file = new StreamReader("TextFile1.txt"))
{
while ((line = file.ReadLine()) != null)
{
counter++;
if (!line.Contains("\"")) continue;
var result = line
.Select((value, index) => new { item = value, position = index })
.Where(item => item.item == '\"')
.ToList();
if (result.Count <= 0) continue;
{
Console.WriteLine($"{line}");
foreach (var item in result)
{
Console.WriteLine(item.position);
}
}
}
}
Text file with sample data
Karen Payne
Jim Jones
Bob "Adams Frank"
Bill Smith
"Jane anne"
Output
Bob "Adams Frank"
4
16
"Jane anne"
0
10
Many many thanks Karen,
that's exactly what I was looking for.
Thanks again
Marco Dell'Oca