473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

VB.NET Fixed String with embedded null characters

2
Hi All,

I am using a com object to maniplate data inside an external program using VB.NET. One of the methods this com object provides requires 1 string parameter.

The external program, however, requires a sting of a specified length, regardless of the number of characters used. The string to be passed to the function (length 36) is a combination of the below key fields.

keyfield 1 length = 2
keyfield 2 length = 7
keyfield 3 length = 10
keyfield 4 length = 6
keyfield 5 length = 14

If the actual value assigned to keyfield 2 has a length less than 7, it should be padded to the right with null characters.

If the actual value assigned to keyfield 3 has a length less than 10, it should be padded to the right with null characters.

If I have the following values:

1: "00"
2: "11111"
3. "123"
4: "XXXXXX"
5: "YYYYYYYYYYYYYY"

I would need the actual values :

keyfield 1 value = "00"
keyfield 2 value = "11111" + chr(0) + chr(0)
keyfield 3 value = "123" + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0)
keyfield 4 value= "XXXXXX"
keyfield 5 value = "YYYYYYYYYYYYYY"

Which, when concatenated, would result in the below key to be passed to com object method:
"0011111 123 XXXXXXYYYYYYYYYYYYYY"

Using a standard .NET string, the first null character (chr(0)) is interpreted as a terminator and the balance of the string is gone.

I have tried the VB6 compatability's VBFixedString type but the com object's method throws an exception due to a type mismatch.

If I convert the VBFixedString back to a .NET string before passing it to the method, the first null character is again interpreted as a string terminator and the rest of my string is chopped.

Does anyone know if there is a way to get around this problem? Any help would be greatly appreciated.
Mar 26 '10 #1
1 4135
Frinavale
9,735 Expert Mod 8TB
Well, in general (C#, C++, Java, C etc etc) Strings are terminated using a null character.

It doesn't make any sense to pad a string with null characters.


Are you certain that you aren't supposed to just pad with space?
Mar 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Danny | last post by:
HI again Is there a nifty function in access that will: 1. return the amount of occurances of a small string within a larger string? this<br>is<br>a<br>test would return 3 for <br>
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
35
by: David Mathog | last post by:
Every so often one of my fgets() based programs encounters an input file containing embedded nulls. fgets is happy to read these but the embedded nulls subsequently cause problems elsewhere in...
15
by: ehabaziz2001 | last post by:
Hi, Till now I do not understand how the null character automatically added to the end of the string and it is not an element of the string array . All books said the null character (\0) added...
1
by: Tajmiester | last post by:
Hi, And thanks for any help. I am having trouble declaring a struct containing strings that can be Serialized using the following functions. It works, but the strings wont store the right number...
2
by: AlanL | last post by:
I am calling a Fortran DLL that has a declaration like: character * 260 variablename. I do not have the Fortran code. A path to a file is passed to the DLL. C# does not have a fixed character...
7
by: JustSomeGuy | last post by:
I need to make a class called uid. A UID is a unique identifier. It looks like... 1.2.3.345.1.2.4.566 This uid get transmitted over a network as 8 bit binary data. If the length of the UID is...
3
by: Tran Hong Quang | last post by:
Hi, I am new to C. How to generate an fixed-length string containing an random digits? for example string of 5 characters, the value can be 03234 or 23423 or 02343 Thanks Tran Hong Quang
3
by: Zach | last post by:
Hello, This might be a rather basic question, but I've tried a few things and I can't really find a solution as elegant as what I'd like for this problem. The situation is this - I have a file...
13
by: Angus | last post by:
Hello I have a stream of bytes - unsigned char*. But the 'string' may contain embedded nulls. So not like a traditional c string terminated with a null. I need to calculate the length of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.