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. String Format Help!

String Format Help!

Scheduled Pinned Locked Moved C#
help
5 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.
  • S Offline
    S Offline
    solutionsville
    wrote on last edited by
    #1

    I have a log that outputs a line like this; BATTERY VOLTAGE RESTORED  Note the blank(whitespace) after the word RESTORED, and then an odd Ascii character at the end. I need to eliminate everything after the word restored and terminate the line at that point. Thanks,

    P 1 Reply Last reply
    0
    • S solutionsville

      I have a log that outputs a line like this; BATTERY VOLTAGE RESTORED  Note the blank(whitespace) after the word RESTORED, and then an odd Ascii character at the end. I need to eliminate everything after the word restored and terminate the line at that point. Thanks,

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      You could iterate through the characters in the string L-R and check the ASCII code of each character. As soon as you find a character whose ASCII code is outside of a certain range e.g. not a letter or number, return a string containing all the characters up to but not including that character. Alternatively, if you know that only the last character isn't needed, use String.Substring to return a string that contains every character in a line minus the last character.

      Paul Marfleet

      S 1 Reply Last reply
      0
      • P pmarfleet

        You could iterate through the characters in the string L-R and check the ASCII code of each character. As soon as you find a character whose ASCII code is outside of a certain range e.g. not a letter or number, return a string containing all the characters up to but not including that character. Alternatively, if you know that only the last character isn't needed, use String.Substring to return a string that contains every character in a line minus the last character.

        Paul Marfleet

        S Offline
        S Offline
        solutionsville
        wrote on last edited by
        #3

        The problem with the L-R is that the ASCII is a random generated item. Not consistant for each entry. I didn't think about the string.substring method. I will have to give that a look. Thanks,

        P 1 Reply Last reply
        0
        • S solutionsville

          The problem with the L-R is that the ASCII is a random generated item. Not consistant for each entry. I didn't think about the string.substring method. I will have to give that a look. Thanks,

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          By L-R I mean process the string contents from left to right. Check each character until you find one whose ASCII code that isn't valid for your purposes. Consult a table of ASCII codes to determine what the valid ranges might be.

          Paul Marfleet

          S 1 Reply Last reply
          0
          • P pmarfleet

            By L-R I mean process the string contents from left to right. Check each character until you find one whose ASCII code that isn't valid for your purposes. Consult a table of ASCII codes to determine what the valid ranges might be.

            Paul Marfleet

            S Offline
            S Offline
            solutionsville
            wrote on last edited by
            #5

            Got it. I think I can mangle it from here!

            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