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 you use a char* in C#?

How do you use a char* in C#?

Scheduled Pinned Locked Moved C#
questioncsharpc++debuggingtutorial
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
    Steve Messer
    wrote on last edited by
    #1

    In C++ I recieved data from a DLLIMPORT call in a char string as follows:

    void funct()
    {
       char *icy=BASS_StreamGetTags( Channel, BASS_TAG_ICY);
    
        for (;*icy;icy+=strlen(icy)+1) 
        {
    	char * lowercase;
    	lowercase = _strlwr(icy);
    
    	if (!memcmp(icy,"title :",7))
    	{
    	    temp = icy;
    	    pCPlayer->WMA_Title = CamelCase(temp.Right(temp.GetLength() - 8));
    	    TRACE("TITLE:"); TRACE( pCPlayer->WMA_Title ); TRACE( "\n");
    	}
    	if (!memcmp(icy,"author :",8))
    	{
    	    temp = icy;
    	    pCPlayer->WMA_Author = CamelCase(temp.Right(temp.GetLength() - 9));
    	    TRACE("AUTHOR:"); TRACE( pCPlayer->WMA_Author ); TRACE( "\n");
    	}		
        }
    }
    

    In C# I am returning the data to a string. How do I walk thru the data in a C# string like I did in the above example?

    G 1 Reply Last reply
    0
    • S Steve Messer

      In C++ I recieved data from a DLLIMPORT call in a char string as follows:

      void funct()
      {
         char *icy=BASS_StreamGetTags( Channel, BASS_TAG_ICY);
      
          for (;*icy;icy+=strlen(icy)+1) 
          {
      	char * lowercase;
      	lowercase = _strlwr(icy);
      
      	if (!memcmp(icy,"title :",7))
      	{
      	    temp = icy;
      	    pCPlayer->WMA_Title = CamelCase(temp.Right(temp.GetLength() - 8));
      	    TRACE("TITLE:"); TRACE( pCPlayer->WMA_Title ); TRACE( "\n");
      	}
      	if (!memcmp(icy,"author :",8))
      	{
      	    temp = icy;
      	    pCPlayer->WMA_Author = CamelCase(temp.Right(temp.GetLength() - 9));
      	    TRACE("AUTHOR:"); TRACE( pCPlayer->WMA_Author ); TRACE( "\n");
      	}		
          }
      }
      

      In C# I am returning the data to a string. How do I walk thru the data in a C# string like I did in the above example?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      How is the data arranged in the string? What is the separator between the strings in the stream? Is it still a zero character? --- b { font-weight: normal; }

      S 1 Reply Last reply
      0
      • G Guffa

        How is the data arranged in the string? What is the separator between the strings in the stream? Is it still a zero character? --- b { font-weight: normal; }

        S Offline
        S Offline
        Steve Messer
        wrote on last edited by
        #3

        The data is a pointer to a series of null-terminated strings is returned, the final string ending with a double null.

        G 1 Reply Last reply
        0
        • S Steve Messer

          The data is a pointer to a series of null-terminated strings is returned, the final string ending with a double null.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          If you have that data in a string, just split it on '\x00' and don't use the last two records in the array, as they will be the strings between the last two terminators and between the last terminator and the end of the string. --- b { font-weight: normal; }

          S 1 Reply Last reply
          0
          • G Guffa

            If you have that data in a string, just split it on '\x00' and don't use the last two records in the array, as they will be the strings between the last two terminators and between the last terminator and the end of the string. --- b { font-weight: normal; }

            S Offline
            S Offline
            Steve Messer
            wrote on last edited by
            #5

            Well I ended up doing the following. When I used string as the return value I was only getting the first chuck of data and not the rest.

            IntPtr icy = BASS_StreamGetTags( radioChan, BASS_TAG_ICY );
            
            byte[] bytetag = new byte[512];
            				
            if (icy != IntPtr.Zero)
            {
                Marshal.Copy(icy, bytetag, 0, bytetag.Length);
            }
            
            ASCIIEncoding encoding = new ASCIIEncoding( );
            string constructedString = encoding.GetString(bytetag);
            
            if (constructedString != string.Empty)
            {
                string tokenizer = "\x00\0";
                string[] token = constructedString.Split( tokenizer.ToCharArray(), 13 );
            }
            

            Thanks for your help

            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