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. VB To C# ( _value = Asc(Mid(LStr, IValue, 1)))

VB To C# ( _value = Asc(Mid(LStr, IValue, 1)))

Scheduled Pinned Locked Moved C#
csharphelp
7 Posts 4 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.
  • B Offline
    B Offline
    blackchaosv2
    wrote on last edited by
    #1

    Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"

    P B D 3 Replies Last reply
    0
    • B blackchaosv2

      Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Mid is the equivalent of Substring. Rather than passing in LStr, you use Substring on that, so you'd have LStr.Substring. LValue is the start position and 1 is the length that you pass in to the Substring method. Asc just returns the ASCII code, so all you need to do is convert the single character from your Substring to an int.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        Mid is the equivalent of Substring. Rather than passing in LStr, you use Substring on that, so you'd have LStr.Substring. LValue is the start position and 1 is the length that you pass in to the Substring method. Asc just returns the ASCII code, so all you need to do is convert the single character from your Substring to an int.

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        B Offline
        B Offline
        blackchaosv2
        wrote on last edited by
        #3

        Thanks I did the following. I added the VisualBasic Reference and used Strings.Asc. Then for the Mid I use:

        public static string Mid(string param, int startIndex, int length)
        {
        string result = param.Substring(startIndex, length);
        return result;
        }

        P 1 Reply Last reply
        0
        • B blackchaosv2

          Thanks I did the following. I added the VisualBasic Reference and used Strings.Asc. Then for the Mid I use:

          public static string Mid(string param, int startIndex, int length)
          {
          string result = param.Substring(startIndex, length);
          return result;
          }

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          blackchaosv2 wrote:

          I added the VisualBasic Reference and used Strings.Asc

          There was no reason to do this. It is easily accomplished without adding a heavy DLL reference. There are many, many ways to get the char out - one way is to use char.Parse(Mid(LStr, startIndex, 1)) and then cast this to an int.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          1 Reply Last reply
          0
          • B blackchaosv2

            Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"

            B Offline
            B Offline
            BobJanova
            wrote on last edited by
            #5

            Is this not just

            char _value = LStr[IValue];

            ... or possibly

            int _value = (int)LStr[IValue];

            ... ?

            1 Reply Last reply
            0
            • B blackchaosv2

              Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"

              D Offline
              D Offline
              Dave Doknjas
              wrote on last edited by
              #6

              Remember, legacy VB string functions are 1-based, not 0-based, so the equivalent is:

              _value = Convert.ToInt32(LStr[IValue - 1]));

              David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter

              P 1 Reply Last reply
              0
              • D Dave Doknjas

                Remember, legacy VB string functions are 1-based, not 0-based, so the equivalent is:

                _value = Convert.ToInt32(LStr[IValue - 1]));

                David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Unless he's got the position using one of the inbuilt .NET routines.

                *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                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