Reputation: 11317
I have this in the top of a Function:
string n = "";
string test = "T256=" + n;
But then test is just "T256="
If in the string n im doing n = "\"";
Then test is "T256=\" but does \ means quotation ?
And how can i take out an empty string for example if i have:
T256="Hello" so i can take out only the Hello but if i have T256="" what does it mean ? Since my program is jumping over an empty string ""
But i need to use it.
For example in my file its like this:
T256="hello"
T256=""
T256=""
T256="hi"
So how do i keep to take in mind the two T256="" ? If i wont it will put the next word in the first empty T256="" and it will be like:
T256="hello"
T256="hi"
And its not the way it should be. It should be in this format this is the good format:
T256="hello"
T256=""
T256=""
T256=hello"
So here is my code where im taking out the text but for some reason it dosent take out places without text in between the two tags.
string startTag = "T256=\""; string endTag = "\"";
If there is a text between this two tags it will take it out but if there is no text between this tags it will jump over to next line with text between the tags.
I need to take any line with T256="" even if its empty between the ""
So in the text file i will see a space or "" for example the text file should looks like:
Hello
""
Hi
""
""
Hello
Or if not "" then empty space and when i put back the text it should also put the spaces or empty strings back too.
This is the code where im taking out the text:
private void parseText(string originalFile, BackgroundWorker worker)
{
FormText("Parsing Text");
int lineNumber = 0;
string startTag = "T256=\"";
string endTag = "\"";
int index = 0;
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
int fileLength = originalFile.Length;
w = new StreamWriter(@"d:\testingdeponias.txt");
while (true)
{
if (index > originalFile.LastIndexOf(startTag))
{
break;
}
int startTagIndex = originalFile.IndexOf(startTag, index);
int stringIndex = startTagIndex + startTagWidth;
index = stringIndex;
int endTagIndex = originalFile.IndexOf(endTag, index);
int stringLength = endTagIndex - stringIndex;
if (stringLength == 0)
{
}
else
{
//worker.ReportProgress(20);
string test = originalFile.Substring(stringIndex, stringLength);
if (test == "")
{
MessageBox.Show(test);
}
But test is never "" i used breakpoint there and its never get to the MessageBox
Upvotes: 2
Views: 155
Reputation: 18508
its very simple.
simply test for
string needle = "256TT=\"\"";
which equals to 256TT=""
and whenever the program finds it, then simply print out your message box or whatever it is you wanted to do: place a space in your text file or place two quotation marks like so \"\"
and thats that.
Upvotes: 1
Reputation: 2163
"\""
means \"
.
In .NET[C#] we cannot simply write "
because this particular Char
has some special function in the Language.
So we have to write the Escape Sequence of the Char "
.
An Escape sequence begins with \
followed by the actual Char.
For Example : Escape sequence of \
is \\
.
So In your case the "
will be written as \"
and to stringify it, \"
becomes "\""
Code :
string n = "\"\"";
string test = "T256=" + n; // same as string test = "T256=\"\""
Read More About Escape Sequence
Upvotes: 2