Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How do i trim down a string[] with - 3 letters??

How do i trim down a string[] with - 3 letters??

Scheduled Pinned Locked Moved C#
questiontutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andredani
    wrote on last edited by
    #1

    Hi i trying to search for values in .txt file and return the existings lines But how can i trim down the string[] Chunk to -3 letters?? for example: .txt file look like this # k441122 blabla blabla blabla blabla if i search for k441 than return the k441122 with all the existings lines? i have tryade Chunk.Substring(0 , 4) Any idea?? My code look like this: private bool ReadChunk(StreamReader sr, out string[] Chunk, string MatchData) { Chunk = new string[9]; bool FoundMatch = false; for (int i = 0; i < 9; i++) { try { Chunk[i] = sr.ReadLine(); if (i == 1 && Chunk[i] == MatchData) { FoundMatch = true; } } catch (Exception ex) { FoundMatch = false; } } return FoundMatch; } Big Tnx!!

    E 1 Reply Last reply
    0
    • A andredani

      Hi i trying to search for values in .txt file and return the existings lines But how can i trim down the string[] Chunk to -3 letters?? for example: .txt file look like this # k441122 blabla blabla blabla blabla if i search for k441 than return the k441122 with all the existings lines? i have tryade Chunk.Substring(0 , 4) Any idea?? My code look like this: private bool ReadChunk(StreamReader sr, out string[] Chunk, string MatchData) { Chunk = new string[9]; bool FoundMatch = false; for (int i = 0; i < 9; i++) { try { Chunk[i] = sr.ReadLine(); if (i == 1 && Chunk[i] == MatchData) { FoundMatch = true; } } catch (Exception ex) { FoundMatch = false; } } return FoundMatch; } Big Tnx!!

      E Offline
      E Offline
      Expert Coming
      wrote on last edited by
      #2

      Use Regex. if (Regex.IsMatch(szStringToSearch, szPatternToFind, RegexOptions.IgnoreCase)) { MessageBox.Show("Success"); }

      The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups