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

  • SEARCH
  • Home
  • 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 6784383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:59:11+00:00 2026-05-26T16:59:11+00:00

I have a txt file as a string, and I need to find words

  • 0

I have a txt file as a string, and I need to find words between two characters and Ltrim/Rtrim everything else. It may have to be conditional because the two characters may change depending on the string.

Example:

car= (data between here I want) ;
car =  (data between here I want) </value>

Code:

int pos = st.LastIndexOf("car=", StringComparison.OrdinalIgnoreCase);

if (pos >= 0)
{
     server = st.Substring(0, pos);..............
}
  • 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-26T16:59:12+00:00Added an answer on May 26, 2026 at 4:59 pm

    This is a simple extension method I use:

    public static string Between(this string src, string findfrom, string findto)
    {
        int start = src.IndexOf(findfrom);
        int to = src.IndexOf(findto, start + findfrom.Length);
        if (start < 0 || to < 0) return "";
        string s = src.Substring(
                       start + findfrom.Length, 
                       to - start - findfrom.Length);
        return s;
    }
    

    With this you can use

    string valueToFind = sourceString.Between("car=", "</value>")
    

    You can also try this:

    public static string Between(this string src, string findfrom, 
                                 params string[] findto)
    {
        int start = src.IndexOf(findfrom);
        if (start < 0) return "";
        foreach (string sto in findto)
        {
            int to = src.IndexOf(sto, start + findfrom.Length);
            if (to >= 0) return
                src.Substring(
                           start + findfrom.Length,
                           to - start - findfrom.Length);
        }
        return "";
    }
    

    With this you can give multiple ending tokens (their order is important)

    string valueToFind = sourceString.Between("car=", ";", "</value>")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big txt file ,with many strings ,say string-I-want-to-change,now I need to
I have a string as below: $str = /dir1/dir2/dir3/file.txt I want to remove the
Ok so I have the following code: string numbers = File.ReadAllText(numbers.txt); StringSplitOptions.RemoveEmptyEntries); List<string> List
I have a .txt file with content(see first image) I need the content in
I need to find out who created a file using .NET I have already
I have a 1.2GB file that contains a one line string. What I need
I have a template file (say myTemplate.txt) and I need to make some edits
I have at base64 encoded string of a image file. I need to save
I have a string from reading a .txt file that looks something like this:
I have quite a large list of words in a txt file and I'm

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.