473,412 Members | 4,966 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,412 software developers and data experts.

String Replace/Registry Manipulation

Hi all,

VB.NET 2003 ONLY PLEASE

I have a registry key (HKCU\Software\Newbie\SomeKey) of type string which
holds an XML string as follows:

<root formID="preferencesform" lang="english" ><global welcome="0"
lang="british" soundEffects="0" soundTheme="default" stayOnTop="0"
autoStart="0" /><main ><pos x="761" y="277" /><size width="240"
height="450" /></main><chat fontFamily="tahoma" fontSize="12"
inMsgColor="255" outMsgColor="3368448" /><video webcam="undefined"
/></root>

I need to read the key from the registry, replace the 'autoStart' value from
0 (zero) to 1 (one) & back using a checkbox control.

'Autostart' starts at character 135 & the zero is 11 characters on making it
char. 146. I will also need to do this for the 'stayOnTop' value too, but
both values will share the same method, just different positions.

How do I do this without creating a temporary XML document, changing it &
writing back to the registry?

TIA
Feb 15 '07 #1
14 1703
Try to use the Replace function.

load reg value into mystring
Replace(mystring, "autoStart=" & chr(34) & "0" & chr(34), "autoStart=" &
chr(34) & "1" & chr(34))
write mystring back to reg
Feb 16 '07 #2
Thanks for your reply. I thought about doing that, but I was also thinking
on the lines of this:

s = "<root formID="preferencesform" lang="english" ><global welcome="0"
lang="british" soundEffects="0" soundTheme="default" stayOnTop="0"
autoStart="0" /><main ><pos x="761" y="277" /><size width="240"
height="450" /></main><chat fontFamily="tahoma" fontSize="12"
inMsgColor="255" outMsgColor="3368448" /><video
webcam="undefined"/></root>"

Dim i As Integer = s.IndexOf("autoStart") ' i = 'a' of autostart
Dim ss As String = s.Substring(i + 11, 1).Replace("0", "1")

Then concatinating the entire string again, but whereas 's' in the example
above held the compulete string at the beginning now it contains just '1'

So, how to I write it back to the entire string?

Any ideas?
Feb 16 '07 #3
I think that you will find that after executing those 2 statements, that s
still holds the while string (unchanged) and that ss has a length of 1 and a
value of "1".

Have you tried simply:

s = s.Replace("autoStart=""0""", "autoStart=""1"")

Also I don't really understand your resistance to using an XmlDocument like
this:

Dim _doc as New XmlDocument
_doc.LoadXml(s)
_doc.SelectSingleNode("//global").Attributes("autoStart").Value = "1"
_s = _doc.OuterXml
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Thanks for your reply. I thought about doing that, but I was also thinking
on the lines of this:

s = "<root formID="preferencesform" lang="english" ><global welcome="0"
lang="british" soundEffects="0" soundTheme="default" stayOnTop="0"
autoStart="0" /><main ><pos x="761" y="277" /><size width="240"
height="450" /></main><chat fontFamily="tahoma" fontSize="12"
inMsgColor="255" outMsgColor="3368448" /><video
webcam="undefined"/></root>"

Dim i As Integer = s.IndexOf("autoStart") ' i = 'a' of autostart
Dim ss As String = s.Substring(i + 11, 1).Replace("0", "1")

Then concatinating the entire string again, but whereas 's' in the example
above held the compulete string at the beginning now it contains just '1'

So, how to I write it back to the entire string?

Any ideas?

Feb 16 '07 #4
Stephany,

The registry key is from a third party application. I will release something
on the net that uses this other application, but I cannot be bothered with
creating a temp XML file just to write back the value of a check_changed
event. It seems pointless & will slow the application down

--
Newbie Coder
(It's just a name)
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I think that you will find that after executing those 2 statements, that s
still holds the while string (unchanged) and that ss has a length of 1 and
a
value of "1".

Have you tried simply:

s = s.Replace("autoStart=""0""", "autoStart=""1"")

Also I don't really understand your resistance to using an XmlDocument
like
this:

Dim _doc as New XmlDocument
_doc.LoadXml(s)
_doc.SelectSingleNode("//global").Attributes("autoStart").Value = "1"
_s = _doc.OuterXml
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Thanks for your reply. I thought about doing that, but I was also
thinking
on the lines of this:

s = "<root formID="preferencesform" lang="english" ><global welcome="0"
lang="british" soundEffects="0" soundTheme="default" stayOnTop="0"
autoStart="0" /><main ><pos x="761" y="277" /><size width="240"
height="450" /></main><chat fontFamily="tahoma" fontSize="12"
inMsgColor="255" outMsgColor="3368448" /><video
webcam="undefined"/></root>"

Dim i As Integer = s.IndexOf("autoStart") ' i = 'a' of autostart
Dim ss As String = s.Substring(i + 11, 1).Replace("0", "1")

Then concatinating the entire string again, but whereas 's' in the
example
above held the compulete string at the beginning now it contains just
'1'

So, how to I write it back to the entire string?

Any ideas?

Feb 16 '07 #5
Stephany,

I think your idea of just replacing the entire autoStart="0"... is the
simplest, quickest solution

Thank you

--
Newbie Coder
(It's just a name)
Feb 16 '07 #6
I also need to read the sutostart value on program startup?

Any ideas?

--
Newbie Coder
(It's just a name)
Feb 17 '07 #7
Ummm ...

Dim _doc as New XmlDocument
_doc.LoadXml(s)
dim autostart As String =
_doc.SelectSingleNode("//global").Attributes("autoStart").Value

I don't know why you think that loading an XML string into an XmlDocument
object is creating a file. All it it doing is parsing it in memory.

In addition I don't know why you think that loading this 'tiny' XML string
into an XmlDocument object is going to create significant overhead to your
program. I'll assume that you are NOT reading this value from the registry
thousands of times in a very short space of time. I think that you will find
that the time to read the value from the registry and load it into an
XmlDocument object on reasonable hardware is less than a single millisecond.

This does beg the question: how often, during the life of an instance of
your program, does an outside entity modify the value in the registry? If
the answer is never then you only need to read it once anyway.
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
>I also need to read the sutostart value on program startup?

Any ideas?

--
Newbie Coder
(It's just a name)

Feb 17 '07 #8
Stephany,

An OT question for me.

Why is it an XML string and an XmlDocument?

I am always automatically writing that and than correcting to

a XML string and a XmlDocument.

To make it on thread.

By the way in my idea is the distinct between a document, a file and a
string is not for everybody obvious and is it used as equivalent.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:OB**************@TK2MSFTNGP03.phx.gbl...
Ummm ...

Dim _doc as New XmlDocument
_doc.LoadXml(s)
dim autostart As String =
_doc.SelectSingleNode("//global").Attributes("autoStart").Value

I don't know why you think that loading an XML string into an XmlDocument
object is creating a file. All it it doing is parsing it in memory.

In addition I don't know why you think that loading this 'tiny' XML string
into an XmlDocument object is going to create significant overhead to your
program. I'll assume that you are NOT reading this value from the registry
thousands of times in a very short space of time. I think that you will
find that the time to read the value from the registry and load it into an
XmlDocument object on reasonable hardware is less than a single
millisecond.

This does beg the question: how often, during the life of an instance of
your program, does an outside entity modify the value in the registry? If
the answer is never then you only need to read it once anyway.
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
>>I also need to read the sutostart value on program startup?

Any ideas?

--
Newbie Coder
(It's just a name)


Feb 17 '07 #9
When I refer to an XML string, I mean a string that contains taext that is
well-formed XML, e.g.:

Dim _s As String = "<Node><<Child>ChildValue</Child></Node>"

When I refer to an XmlDocument I mean an object of type System.XmlDocument.

As you can see I was pointing out to the OP that an XmlDocument is NOT a
file, although it can be loaded from a file.

The distinction is very important and, as you are well aware, the use of
incorrect terminology can get one into a lot of trouble, especially in these
newsgroups.

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Stephany,

An OT question for me.

Why is it an XML string and an XmlDocument?

I am always automatically writing that and than correcting to

a XML string and a XmlDocument.

To make it on thread.

By the way in my idea is the distinct between a document, a file and a
string is not for everybody obvious and is it used as equivalent.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:OB**************@TK2MSFTNGP03.phx.gbl...
>Ummm ...

Dim _doc as New XmlDocument
_doc.LoadXml(s)
dim autostart As String =
_doc.SelectSingleNode("//global").Attributes("autoStart").Value

I don't know why you think that loading an XML string into an XmlDocument
object is creating a file. All it it doing is parsing it in memory.

In addition I don't know why you think that loading this 'tiny' XML
string into an XmlDocument object is going to create significant overhead
to your program. I'll assume that you are NOT reading this value from the
registry thousands of times in a very short space of time. I think that
you will find that the time to read the value from the registry and load
it into an XmlDocument object on reasonable hardware is less than a
single millisecond.

This does beg the question: how often, during the life of an instance of
your program, does an outside entity modify the value in the registry? If
the answer is never then you only need to read it once anyway.
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
>>>I also need to read the sutostart value on program startup?

Any ideas?

--
Newbie Coder
(It's just a name)


Feb 17 '07 #10
Oh, I see what you are asking!

In English, there are 2 forms of the indefinite article, 'a' and 'an'.

The form 'an' is used when it precedes a noun that starts with a vowel
sound, regardless of whether or not it actually starts with a vowel.

Although 'X' is not vowel, it's sound is as if it was 'EX' and theefore the
'an' form of the indefinite article applies.

Just to confuse the issue, in spoken English, you often hear someone say 'an
Hotel' which, of course, appearsis incorrect. They should say 'a Hotel', but
in absolutely correct English the 'H' sound is dropped in the word 'Hotel'
and it is pronounced 'Otel'. This makes 'an Otel' correct.

In written English, however, the 'H' is not dropped from the wiord 'Hotel'
and there fore the written from should always be 'a Hotel".

Just another of the vagaries and nuances of our marvelous English language
that are there just to confuse those for whom English is not thier first
language :)

While we're on the subject and for your edification, you tend to use the
word 'than' where you should use the word 'then', and it does make reading
some of your posts difficult.

'than' is a conjunction to show comparison as in 'I am older than you'.

'then' is primarily used as an adverb and has a variety of meanings
depending on the context. On meaning is to show a progresion as in 'If
<conditionThen <statement>' which you will be familiar with.

Your statement 'I am always automatically writing that and than correcting
to ...' should have been 'I am always automatically writing that and then
correcting to ...'.

And there endeth the English lesson for the day :)
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Stephany,

An OT question for me.

Why is it an XML string and an XmlDocument?

I am always automatically writing that and than correcting to

a XML string and a XmlDocument.

To make it on thread.

By the way in my idea is the distinct between a document, a file and a
string is not for everybody obvious and is it used as equivalent.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:OB**************@TK2MSFTNGP03.phx.gbl...
>Ummm ...

Dim _doc as New XmlDocument
_doc.LoadXml(s)
dim autostart As String =
_doc.SelectSingleNode("//global").Attributes("autoStart").Value

I don't know why you think that loading an XML string into an XmlDocument
object is creating a file. All it it doing is parsing it in memory.

In addition I don't know why you think that loading this 'tiny' XML
string into an XmlDocument object is going to create significant overhead
to your program. I'll assume that you are NOT reading this value from the
registry thousands of times in a very short space of time. I think that
you will find that the time to read the value from the registry and load
it into an XmlDocument object on reasonable hardware is less than a
single millisecond.

This does beg the question: how often, during the life of an instance of
your program, does an outside entity modify the value in the registry? If
the answer is never then you only need to read it once anyway.
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
>>>I also need to read the sutostart value on program startup?

Any ideas?

--
Newbie Coder
(It's just a name)


Feb 17 '07 #11
Stephany,,

The Than and Then is in Dutch one word (spoken not so different as in
English Than) "Dan".

I go automatically go for the "than" word when it is not the action as
result from a compare. I will change that and take it for every action.

Thank you very much.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:ul**************@TK2MSFTNGP06.phx.gbl...
Oh, I see what you are asking!

In English, there are 2 forms of the indefinite article, 'a' and 'an'.

The form 'an' is used when it precedes a noun that starts with a vowel
sound, regardless of whether or not it actually starts with a vowel.

Although 'X' is not vowel, it's sound is as if it was 'EX' and theefore
the 'an' form of the indefinite article applies.

Just to confuse the issue, in spoken English, you often hear someone say
'an Hotel' which, of course, appearsis incorrect. They should say 'a
Hotel', but in absolutely correct English the 'H' sound is dropped in the
word 'Hotel' and it is pronounced 'Otel'. This makes 'an Otel' correct.

In written English, however, the 'H' is not dropped from the wiord 'Hotel'
and there fore the written from should always be 'a Hotel".

Just another of the vagaries and nuances of our marvelous English language
that are there just to confuse those for whom English is not thier first
language :)

While we're on the subject and for your edification, you tend to use the
word 'than' where you should use the word 'then', and it does make reading
some of your posts difficult.

'than' is a conjunction to show comparison as in 'I am older than you'.

'then' is primarily used as an adverb and has a variety of meanings
depending on the context. On meaning is to show a progresion as in 'If
<conditionThen <statement>' which you will be familiar with.

Your statement 'I am always automatically writing that and than correcting
to ...' should have been 'I am always automatically writing that and then
correcting to ...'.

And there endeth the English lesson for the day :)
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Stephany,

An OT question for me.

Why is it an XML string and an XmlDocument?

I am always automatically writing that and than correcting to

a XML string and a XmlDocument.

To make it on thread.

By the way in my idea is the distinct between a document, a file and a
string is not for everybody obvious and is it used as equivalent.

Cor

"Stephany Young" <noone@localhostschreef in bericht
news:OB**************@TK2MSFTNGP03.phx.gbl...
>>Ummm ...

Dim _doc as New XmlDocument
_doc.LoadXml(s)
dim autostart As String =
_doc.SelectSingleNode("//global").Attributes("autoStart").Value

I don't know why you think that loading an XML string into an
XmlDocument object is creating a file. All it it doing is parsing it in
memory.

In addition I don't know why you think that loading this 'tiny' XML
string into an XmlDocument object is going to create significant
overhead to your program. I'll assume that you are NOT reading this
value from the registry thousands of times in a very short space of
time. I think that you will find that the time to read the value from
the registry and load it into an XmlDocument object on reasonable
hardware is less than a single millisecond.

This does beg the question: how often, during the life of an instance of
your program, does an outside entity modify the value in the registry?
If the answer is never then you only need to read it once anyway.
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
I also need to read the sutostart value on program startup?

Any ideas?

--
Newbie Coder
(It's just a name)


Feb 18 '07 #12
It seems that the third party application isn't reading the value from the
registry because I have tested it & the Start With Windows value stays
unchecked within their application when I change the registry setting the
the XML string

The reason I am not creating the XML Doc is because I couldn't be bothered.
If I did I would have written it 3 days ago.

Anyway. The apps on hold for a few days as I have to install a graphics card
for someone, reformat a laptop for another, install a wireless system for
another, upgrade a 20 user network; workstations, servers & cabling not
forgetting the data migration etc. So, I am busy enough for a few day then I
am flying to Sweden. Will check this post as & when I have the chance

Laters
Feb 18 '07 #13
Ah well, there you have it.

If you can't be bothered then neither can I.
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
It seems that the third party application isn't reading the value from the
registry because I have tested it & the Start With Windows value stays
unchecked within their application when I change the registry setting the
the XML string

The reason I am not creating the XML Doc is because I couldn't be
bothered.
If I did I would have written it 3 days ago.

Anyway. The apps on hold for a few days as I have to install a graphics
card
for someone, reformat a laptop for another, install a wireless system for
another, upgrade a 20 user network; workstations, servers & cabling not
forgetting the data migration etc. So, I am busy enough for a few day then
I
am flying to Sweden. Will check this post as & when I have the chance

Laters

Feb 19 '07 #14
There is no point in creating a XML file

--
Newbie Coder
(It's just a name)
Feb 19 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phrederik | last post by:
Hey all! New to javascript and still getting my head around strings... Consider the following line of code... var path = location.pathname; ....after execution, the variable "path"...
12
by: Hp | last post by:
Hi All, Thanks a lot for all your replies. My requirement is as follows: I need to read a text file, eliminate certain special characters(like ! , - = + ), and then convert it to lower case and...
4
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
5
by: Niyazi | last post by:
Hi, Does anyone knows any good code for string manipulation similar to RegularExpresion? I might get a value as string in a different format. Example: 20/02/2006 or 20,02,2006 or ...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
5
by: Hels Bells | last post by:
Hi, I'm looking to do some manipulation on a string containing html code in asp which will involve me either using some regular expressions or just plain old simple replace functionality. The...
8
by: ross m. greenberg | last post by:
I'm trying to emulate the look and feel of "RegEdit" under Visual Basic/VB.Net using Visual Studio 2005. Can anybody give me a pointer in the right direction: for example, what name spaces must I...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.