Re: ASCII Low Values (Ascii 0) to a string

  • Thread starter Thread starter Manfred Suttorp
  • Start date Start date
M

Manfred Suttorp

Jeff said:
I'm writing a VB Class that will be calling a COBOL.net class.
I need to put ASCII Low values into a string to pass to the COBOL.Net
method.
The COBOL accepts a large structure, and i need to pad some values
with low values (to "Null" them, and still preserve the spacing in the
structure)... The trouble i'm having is how can i put ASCII 0's into
my VB string?

Well, In C# you can just concatenate string and char types. I suppose VB
supports that as well.
Maybe this C# fragment will help you a bit:

string str = "sometext" + (char)0;

Regards,
Manfred
 
Manfred Suttorp said:
Well, In C# you can just concatenate string and char types. I suppose VB
supports that as well.
Maybe this C# fragment will help you a bit:

string str = "sometext" + (char)0;

As an alternative, in C# you could just use:

string str = "sometext\0";

Unfortunately I don't believe there's any equivalent to that in VB :(
 
Hey guys, thanks so much for the help!
In the end i used char.MinValue to build a string of low values that i
the used to concatenate onto my string as i was building it. Here is
some code:

private _myVariable as String

Dim lowValues as String
Dim sb as New StringBuilder
Dim tempString as String

For i = 1 To 85
lowValues = lowValues & Char.MinValue
Next

_myVariable1 = Left(lowValues, 10)

sb.Append(_myVariable1)
...
...

tempString = sb.ToString

This worked well for me, as the low values take up the space i need,
and I'm not doing any further string operations (just passing it to
the COBOL). However, not all of the String functions like having the
low values in them... for example if i did:
tempString.Length i would get 674

however if i did:
tempString.ToString.Length i would get 18 (where my first ASCII(0)
would occur)

also, if did
mid(tempString, 300, 8) i would get '20030420'

however if i did:
instr(tempString, '20030420') i would get 0...

so somethings work and some things don't... as I said, it does what i
need it to.


jeffpriz
 
Back
Top