C# Convert REG_MULTI_SZ value in text file to String The Next CEO of Stack OverflowWhat is the difference between String and string in C#?Convert a string to an enum in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?Case insensitive 'Contains(string)'Best practice to save application settings in a Windows Forms ApplicationHow do I get a consistent byte representation of strings in C# without manually specifying an encoding?Get int value from enum in C#Best way to read a large file into a byte array in C#?

Prepend last line of stdin to entire stdin

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Unclear about dynamic binding

Is it possible to use a NPN BJT as switch, from single power source?

Axiom Schema vs Axiom

How to get from Geneva Airport to Metabief, Doubs, France by public transport?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Does Germany produce more waste than the US?

How to edit “Name” property in GCI output?

Is it convenient to ask the journal's editor for two additional days to complete a review?

Why do remote US companies require working in the US?

What happened in Rome, when the western empire "fell"?

Where do students learn to solve polynomial equations these days?

Easy to read palindrome checker

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Reference request: Grassmannian and Plucker coordinates in type B, C, D

What steps are necessary to read a Modern SSD in Medieval Europe?

Grabbing quick drinks

Why does standard notation not preserve intervals (visually)

Find non-case sensitive string in a mixed list of elements?

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

A small doubt about the dominated convergence theorem



C# Convert REG_MULTI_SZ value in text file to String



The Next CEO of Stack OverflowWhat is the difference between String and string in C#?Convert a string to an enum in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?Case insensitive 'Contains(string)'Best practice to save application settings in a Windows Forms ApplicationHow do I get a consistent byte representation of strings in C# without manually specifying an encoding?Get int value from enum in C#Best way to read a large file into a byte array in C#?










0















I am not a trained programmer but I do write some code (so be gentle). I am working on code to read a registry file and store the values in an SQL database. We have different registry files we push depending on the computer build. And while I could keep a folder of registry files, having a database makes it easier to compare differences and keep track of changes to the registry settings.



That said, I can easily read string and dword values but I'm having trouble with the REG_MULTI_SZ values. For example, how do I convert this in the registry file?



"SampleMS"=hex(7):54,00,45,00,53,00,54,00,00,00,44,00,41,00,54,00,41,00,00,00,
00,00

(This is 2 lines of text in the registry file so I know i have to account or that.)



To the actual value shown in regedit of:
TEST
DATA



I've read several examples of hex to byte array and byte array to string, but all that seems to do is give me the hex values in a string format like "5400450053..."



If this has already been answered somewhere and I missed it, my apologies. Any examples or code snippets are appreciated. Thank you.










share|improve this question
























  • Don't you mean "REG_MULTI_SZ"?

    – rory.ap
    Mar 8 at 15:09











  • Also the data you have looks like binary (REG_BINARY), not strings.

    – rory.ap
    Mar 8 at 15:10












  • Sorry, yes. REG_MULTI_SZ. It's not a REG_BINARY although it appears to be binary data. It's the value that goes into the text file when you export the key. So my REG_MULTI_SZ is named SampleMS and the data in that value is TEST DATA on 2 separate lines.

    – Tim Falk
    Mar 8 at 15:22












  • Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)

    – Damien_The_Unbeliever
    Mar 8 at 15:23












  • OK. So my guess would be I need to convert 54,00 to 2 decimal equivalents and then get the ASCII character of the decimal value? And I'd throw away the 00 unless there are 2 in a row and that indicates a new line? This doesn't have to perform quickly, just work.

    – Tim Falk
    Mar 8 at 15:28















0















I am not a trained programmer but I do write some code (so be gentle). I am working on code to read a registry file and store the values in an SQL database. We have different registry files we push depending on the computer build. And while I could keep a folder of registry files, having a database makes it easier to compare differences and keep track of changes to the registry settings.



That said, I can easily read string and dword values but I'm having trouble with the REG_MULTI_SZ values. For example, how do I convert this in the registry file?



"SampleMS"=hex(7):54,00,45,00,53,00,54,00,00,00,44,00,41,00,54,00,41,00,00,00,
00,00

(This is 2 lines of text in the registry file so I know i have to account or that.)



To the actual value shown in regedit of:
TEST
DATA



I've read several examples of hex to byte array and byte array to string, but all that seems to do is give me the hex values in a string format like "5400450053..."



If this has already been answered somewhere and I missed it, my apologies. Any examples or code snippets are appreciated. Thank you.










share|improve this question
























  • Don't you mean "REG_MULTI_SZ"?

    – rory.ap
    Mar 8 at 15:09











  • Also the data you have looks like binary (REG_BINARY), not strings.

    – rory.ap
    Mar 8 at 15:10












  • Sorry, yes. REG_MULTI_SZ. It's not a REG_BINARY although it appears to be binary data. It's the value that goes into the text file when you export the key. So my REG_MULTI_SZ is named SampleMS and the data in that value is TEST DATA on 2 separate lines.

    – Tim Falk
    Mar 8 at 15:22












  • Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)

    – Damien_The_Unbeliever
    Mar 8 at 15:23












  • OK. So my guess would be I need to convert 54,00 to 2 decimal equivalents and then get the ASCII character of the decimal value? And I'd throw away the 00 unless there are 2 in a row and that indicates a new line? This doesn't have to perform quickly, just work.

    – Tim Falk
    Mar 8 at 15:28













0












0








0








I am not a trained programmer but I do write some code (so be gentle). I am working on code to read a registry file and store the values in an SQL database. We have different registry files we push depending on the computer build. And while I could keep a folder of registry files, having a database makes it easier to compare differences and keep track of changes to the registry settings.



That said, I can easily read string and dword values but I'm having trouble with the REG_MULTI_SZ values. For example, how do I convert this in the registry file?



"SampleMS"=hex(7):54,00,45,00,53,00,54,00,00,00,44,00,41,00,54,00,41,00,00,00,
00,00

(This is 2 lines of text in the registry file so I know i have to account or that.)



To the actual value shown in regedit of:
TEST
DATA



I've read several examples of hex to byte array and byte array to string, but all that seems to do is give me the hex values in a string format like "5400450053..."



If this has already been answered somewhere and I missed it, my apologies. Any examples or code snippets are appreciated. Thank you.










share|improve this question
















I am not a trained programmer but I do write some code (so be gentle). I am working on code to read a registry file and store the values in an SQL database. We have different registry files we push depending on the computer build. And while I could keep a folder of registry files, having a database makes it easier to compare differences and keep track of changes to the registry settings.



That said, I can easily read string and dword values but I'm having trouble with the REG_MULTI_SZ values. For example, how do I convert this in the registry file?



"SampleMS"=hex(7):54,00,45,00,53,00,54,00,00,00,44,00,41,00,54,00,41,00,00,00,
00,00

(This is 2 lines of text in the registry file so I know i have to account or that.)



To the actual value shown in regedit of:
TEST
DATA



I've read several examples of hex to byte array and byte array to string, but all that seems to do is give me the hex values in a string format like "5400450053..."



If this has already been answered somewhere and I missed it, my apologies. Any examples or code snippets are appreciated. Thank you.







c# registry






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 15:23







Tim Falk

















asked Mar 8 at 15:06









Tim FalkTim Falk

12




12












  • Don't you mean "REG_MULTI_SZ"?

    – rory.ap
    Mar 8 at 15:09











  • Also the data you have looks like binary (REG_BINARY), not strings.

    – rory.ap
    Mar 8 at 15:10












  • Sorry, yes. REG_MULTI_SZ. It's not a REG_BINARY although it appears to be binary data. It's the value that goes into the text file when you export the key. So my REG_MULTI_SZ is named SampleMS and the data in that value is TEST DATA on 2 separate lines.

    – Tim Falk
    Mar 8 at 15:22












  • Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)

    – Damien_The_Unbeliever
    Mar 8 at 15:23












  • OK. So my guess would be I need to convert 54,00 to 2 decimal equivalents and then get the ASCII character of the decimal value? And I'd throw away the 00 unless there are 2 in a row and that indicates a new line? This doesn't have to perform quickly, just work.

    – Tim Falk
    Mar 8 at 15:28

















  • Don't you mean "REG_MULTI_SZ"?

    – rory.ap
    Mar 8 at 15:09











  • Also the data you have looks like binary (REG_BINARY), not strings.

    – rory.ap
    Mar 8 at 15:10












  • Sorry, yes. REG_MULTI_SZ. It's not a REG_BINARY although it appears to be binary data. It's the value that goes into the text file when you export the key. So my REG_MULTI_SZ is named SampleMS and the data in that value is TEST DATA on 2 separate lines.

    – Tim Falk
    Mar 8 at 15:22












  • Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)

    – Damien_The_Unbeliever
    Mar 8 at 15:23












  • OK. So my guess would be I need to convert 54,00 to 2 decimal equivalents and then get the ASCII character of the decimal value? And I'd throw away the 00 unless there are 2 in a row and that indicates a new line? This doesn't have to perform quickly, just work.

    – Tim Falk
    Mar 8 at 15:28
















Don't you mean "REG_MULTI_SZ"?

– rory.ap
Mar 8 at 15:09





Don't you mean "REG_MULTI_SZ"?

– rory.ap
Mar 8 at 15:09













Also the data you have looks like binary (REG_BINARY), not strings.

– rory.ap
Mar 8 at 15:10






Also the data you have looks like binary (REG_BINARY), not strings.

– rory.ap
Mar 8 at 15:10














Sorry, yes. REG_MULTI_SZ. It's not a REG_BINARY although it appears to be binary data. It's the value that goes into the text file when you export the key. So my REG_MULTI_SZ is named SampleMS and the data in that value is TEST DATA on 2 separate lines.

– Tim Falk
Mar 8 at 15:22






Sorry, yes. REG_MULTI_SZ. It's not a REG_BINARY although it appears to be binary data. It's the value that goes into the text file when you export the key. So my REG_MULTI_SZ is named SampleMS and the data in that value is TEST DATA on 2 separate lines.

– Tim Falk
Mar 8 at 15:22














Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)

– Damien_The_Unbeliever
Mar 8 at 15:23






Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)

– Damien_The_Unbeliever
Mar 8 at 15:23














OK. So my guess would be I need to convert 54,00 to 2 decimal equivalents and then get the ASCII character of the decimal value? And I'd throw away the 00 unless there are 2 in a row and that indicates a new line? This doesn't have to perform quickly, just work.

– Tim Falk
Mar 8 at 15:28





OK. So my guess would be I need to convert 54,00 to 2 decimal equivalents and then get the ASCII character of the decimal value? And I'd throw away the 00 unless there are 2 in a row and that indicates a new line? This doesn't have to perform quickly, just work.

– Tim Falk
Mar 8 at 15:28












1 Answer
1






active

oldest

votes


















0














Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)



So, steps to take - take each pair of hex characters and turn those into a byte (plenty of examples for doing this around). Then take this array of bytes and using System.Text.Encoding.Unicode to turn those bytes into a string. Most systems these days are fine with strings containing null characters, and here they mark the delimiters, so if you want to split it into the individual strings, split on the nulls after the string conversion.



However, if you just want to store these strings and whatever DB you're working with is fine with null characters in strings, pass them through unchanged. Note: If you've not been using parameterized queries up until this point in accessing the database, now's the time to learn. Because it's often tricky to construct a string literal which contains a null character without having to do lots of manual re-processing and/or escaping. And it's generally a good habit.




Your string here should contain the characters T, E, S, T, null, D, A, T, A, null, null






share|improve this answer

























  • Thank you. This is exactly the direction I needed. Appreciate the push.

    – Tim Falk
    Mar 8 at 16:58











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065947%2fc-sharp-convert-reg-multi-sz-value-in-text-file-to-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)



So, steps to take - take each pair of hex characters and turn those into a byte (plenty of examples for doing this around). Then take this array of bytes and using System.Text.Encoding.Unicode to turn those bytes into a string. Most systems these days are fine with strings containing null characters, and here they mark the delimiters, so if you want to split it into the individual strings, split on the nulls after the string conversion.



However, if you just want to store these strings and whatever DB you're working with is fine with null characters in strings, pass them through unchanged. Note: If you've not been using parameterized queries up until this point in accessing the database, now's the time to learn. Because it's often tricky to construct a string literal which contains a null character without having to do lots of manual re-processing and/or escaping. And it's generally a good habit.




Your string here should contain the characters T, E, S, T, null, D, A, T, A, null, null






share|improve this answer

























  • Thank you. This is exactly the direction I needed. Appreciate the push.

    – Tim Falk
    Mar 8 at 16:58















0














Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)



So, steps to take - take each pair of hex characters and turn those into a byte (plenty of examples for doing this around). Then take this array of bytes and using System.Text.Encoding.Unicode to turn those bytes into a string. Most systems these days are fine with strings containing null characters, and here they mark the delimiters, so if you want to split it into the individual strings, split on the nulls after the string conversion.



However, if you just want to store these strings and whatever DB you're working with is fine with null characters in strings, pass them through unchanged. Note: If you've not been using parameterized queries up until this point in accessing the database, now's the time to learn. Because it's often tricky to construct a string literal which contains a null character without having to do lots of manual re-processing and/or escaping. And it's generally a good habit.




Your string here should contain the characters T, E, S, T, null, D, A, T, A, null, null






share|improve this answer

























  • Thank you. This is exactly the direction I needed. Appreciate the push.

    – Tim Falk
    Mar 8 at 16:58













0












0








0







Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)



So, steps to take - take each pair of hex characters and turn those into a byte (plenty of examples for doing this around). Then take this array of bytes and using System.Text.Encoding.Unicode to turn those bytes into a string. Most systems these days are fine with strings containing null characters, and here they mark the delimiters, so if you want to split it into the individual strings, split on the nulls after the string conversion.



However, if you just want to store these strings and whatever DB you're working with is fine with null characters in strings, pass them through unchanged. Note: If you've not been using parameterized queries up until this point in accessing the database, now's the time to learn. Because it's often tricky to construct a string literal which contains a null character without having to do lots of manual re-processing and/or escaping. And it's generally a good habit.




Your string here should contain the characters T, E, S, T, null, D, A, T, A, null, null






share|improve this answer















Well, those bytes appear to be UTF16 representations of characters. A MULTI_SZ contains multiple null-terminated strings terminated by an empty string (or, if you like by two null terminating characters, but technically the first of those "belongs" to the previous string). You've shown us two strings of 4 characters each (plus null characters and the end)



So, steps to take - take each pair of hex characters and turn those into a byte (plenty of examples for doing this around). Then take this array of bytes and using System.Text.Encoding.Unicode to turn those bytes into a string. Most systems these days are fine with strings containing null characters, and here they mark the delimiters, so if you want to split it into the individual strings, split on the nulls after the string conversion.



However, if you just want to store these strings and whatever DB you're working with is fine with null characters in strings, pass them through unchanged. Note: If you've not been using parameterized queries up until this point in accessing the database, now's the time to learn. Because it's often tricky to construct a string literal which contains a null character without having to do lots of manual re-processing and/or escaping. And it's generally a good habit.




Your string here should contain the characters T, E, S, T, null, D, A, T, A, null, null







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 8 at 15:43

























answered Mar 8 at 15:37









Damien_The_UnbelieverDamien_The_Unbeliever

198k17256346




198k17256346












  • Thank you. This is exactly the direction I needed. Appreciate the push.

    – Tim Falk
    Mar 8 at 16:58

















  • Thank you. This is exactly the direction I needed. Appreciate the push.

    – Tim Falk
    Mar 8 at 16:58
















Thank you. This is exactly the direction I needed. Appreciate the push.

– Tim Falk
Mar 8 at 16:58





Thank you. This is exactly the direction I needed. Appreciate the push.

– Tim Falk
Mar 8 at 16:58



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065947%2fc-sharp-convert-reg-multi-sz-value-in-text-file-to-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived