Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:20:48+00:00 2026-05-30T11:20:48+00:00

This is the code: private void retrivingText1() { string startTag = zethrone1_03510;//<Translation>; string endTag

  • 0

This is the code:

private void retrivingText1()
{
   string startTag = "zethrone1_03510";//"<Translation>";
   string endTag = "-2.8";//"</Translation>";

   int startTagWidth = startTag.Length;
   int endTagWidth = endTag.Length;
   index = 0;

   w = new StreamWriter(@"d:\retrivedText1.txt");

   while (true)
   {
      index = f.IndexOf(startTag, index);

      if (index == -1)
      {
         break;
      }

      // else more to do - index now is positioned at first character of startTag 
      int start = index + startTagWidth;
      index = f.IndexOf(endTag, start + 1);

      if (index == -1)
      {
         break;
      }

      // found the endTag 
      string g = f.Substring(start, index - start);
      w.WriteLine(g);
   }

   w.Close();
}

The first work in the file that I want to retrieve is Hallo? which is coming right after zethrone1_03510 but between zethrone1_03510 and Hallo? there are two spaces so I’m getting it in the new text file like this Hallo?

And I want it to be Hallo? without the two spaces after zethrone1_03510 that’s one problem.

The second problem is that in the end of the file there is a text -2.8 so I want to retrieve all the text from the first Hallo? including it until the end of the file or until the last -2.8 including it too. Since there are more places after the Hallo? with -2.8

I tried to use LastIndexOf instead of IndexOf but it didn’t work.

And I know there are other ways but I want to do it with my code to fix/repair my code not using another way of codes. Whats wrong here ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:20:50+00:00Added an answer on May 30, 2026 at 11:20 am

    For your first problem you could use the Trim() method to get rid of the space. you could Trim your resulting string like: (" Hallo").Trim(); or variable.Trim(); which results in “Hallo”.

    LastIndexOf should work with your second problem . You could use int position = f.LastIndexOf (endTag); And after you found the text you should break from the loop so you don’t have an endless loop.

    http://msdn.microsoft.com/en-us/library/0w96zd3d.aspx

    private void retrivingText1()
    {
        string startTag = "zethrone1_03510";//"<Translation>";
        string endTag = "-2.8";//"</Translation>";
        int startTagWidth = startTag.Length;
        int endTagWidth = endTag.Length;
        index = 0;
        w = new StreamWriter(@"d:\retrivedText1.txt");
        while (true)
        {
            index = f.IndexOf(startTag, index);
            if (index == -1)
            {
                break;
            }
            // else more to do - index now is positioned at first character of startTag 
            int start = index + startTagWidth;
            index = f.LastIndexOf (endTag, start + 1);
            if (index == -1)
            {
                break;
            }
            // found the endTag 
            string g = f.Substring(start, index - start + endTagWidth).Trim(); //Trim the founded text so the start and ending spaces are removed.
            w.WriteLine(g);
            //break so you dont have an endless loop
            break;
        }
        w.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: private void SaveStreamToFile(string fileFullPath, Stream stream) { if (stream.Length ==
I have this code private void writeReport(IReport report, string reportName) { string reportString =
This code compiles: private static void Main(string[] args) { bool? fred = true; if
this is my code private void sendToClient(Dictionary<string, string> reportDic) { Response.Clear(); Response.BufferOutput = false;
In this code private void btnConnect_Click(object sender, EventArgs e) { string localHost = 192.168.10.3;
I am serializing an structure by using BinaryFormatter using this code: private void SerializeObject(string
I have this code: private void timer_Tick(object sender, EventArgs e) { timer.Stop(); for (int
Could you please explain why this code is not syntactically correct? private void addEditor(final
I have this piece of code in c#: private static void _constructRow(SqlDataReader reader, system.IO.StreamWriter
Got this line of code here but its not working. private void Button_Click(object sender,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.