IronPython convert from Python String to SByte array
Question: for the usage of an external dll in IronPython I have to pass a string to a
**char array** (char var[len]; in C++.NET). It seems to be expected to pass an
SByte array.

If I try

    
    
    myVarFromCLibrary = myPyString
    

I get

    
    
    TypeError: expected Array[SByte], got str
    

There is very little information in the web. Up to now I found that I can
apply something like this:

    
    
    from System import Array
    ...
    myCString = Array[System.SByte](myPyString)
    
    myVarFromCLibrary = myCString
    

If I do so, I get an error like:

    
    
    TypeError: expected SByte, got str
    

What is to do to get the right conversion.


Answer: Meanwhile I found a workaround but no solution:

    
    
    def strToCharArray(theCharArray,theString):
      asBytes = bytes(theString,'ascii')  
      for i in xrange(len(theString)):
        theCharArray[i] = ord(asBytes[i])
      theCharArray[len(asBytes)] = 0
    
    def charArrayToStr(theCharArray):  
      chars = []
      i     = 0
      while theCharArray[i]>0: 
        chars.append(chr(theCharArray[i]))
        i += 1
      return "".join(chars)
    

This keeps my program running but is not the real solution

