For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > August 2005 > String.Replace not working???









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author String.Replace not working???
BBM

2005-08-03, 5:06 pm

This is so bizarre I hesitate to post it, but I need to get this working.

My code looks like this...

Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _
" WHERE Scenario =
@Scenario"
Dim cmdstr as String

cmdstr = cmdTestResourcesSel
If history Then
cmdstr.Replace("TResources", "TResourcesHistory")
End If
Dim cmdS As SqlCommand = New SqlCommand(cmdstr, cnTest)

History is true. Coming out of the "if" statement, cmdstr is unchanged.
CommandText of the SQLCommand contains "TResources" not "TResourcesHistory"
This same code template works in the same program in about a dozen other
places. No exceptions thrown. I can do the replace on cmdstr in the
command window while debugging the app and it works fine.

What's up with this???

Thanks for your help.

BBM
Rick Rothstein [MVP - Visual Basic]

2005-08-03, 5:06 pm

> cmdstr.Replace("TResources", "TResourcesHistory")

cmdstr.Replace? Is this a VB.NET question?

Almost everybody in this newsgroup is using VB6 or lower. While you may
get a stray answer to VB.NET (including VB2003 and VB2005 which has
dropped .NET from its name) questions here, you should ask them in
newsgroups devoted exclusively to .NET programming. Look for newsgroups
with either the word "dotnet" or "vsnet" in their name.

For the microsoft news server, try these newsgroups for Visual Basic
..NET related questions...

microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.upgrade
microsoft.public.dotnet.languages.vb.controls
microsoft.public.dotnet.languages.vb.data

And these for more general .NET questions

microsoft.public.dotnet.general
microsoft.public.vsnet.general

Note: There are many other .NET newgroups (use the first three "fields"
from the last two as templates when searching for them), but the above
ones should get you started.

Rick




Bob Butler

2005-08-03, 5:06 pm

"BBM" <bbm@bbmcompany.com> wrote in message news:D4E47088-A36D-4635-
85CC-EB723E83AF08@microsoft.com
> This is so bizarre I hesitate to post it, but I need to get this
> working.



--
<response type="generic" language="VB.Net">
This newsgroup is for users of Visual Basic version 6.0
and earlier and not the misleadingly named VB.Net
or VB 200x. Solutions, and often even the questions,
for one platform will be meaningless in the other.
When VB.Net was released Microsoft created new newsgroups
devoted to the new platform so that neither group of
developers need wade through the clutter of unrelated
topics. Look for newsgroups with the words "dotnet" or
"vsnet" in their name. For the msnews.microsoft.com news
server try these:

microsoft.public.dotnet.general
microsoft.public.dotnet.languages.vb

</response>

BBM

2005-08-03, 5:06 pm

Sorry for mis-posting my question. It's so basic that I had to hunt for
someplace to post it and I obviously picked the wrong place.

PS. I wish the VB.Net folks would respond as quickly ;)

Thanks.

"Rick Rothstein [MVP - Visual Basic]" wrote:

>
> cmdstr.Replace? Is this a VB.NET question?
>
> Almost everybody in this newsgroup is using VB6 or lower. While you may
> get a stray answer to VB.NET (including VB2003 and VB2005 which has
> dropped .NET from its name) questions here, you should ask them in
> newsgroups devoted exclusively to .NET programming. Look for newsgroups
> with either the word "dotnet" or "vsnet" in their name.
>
> For the microsoft news server, try these newsgroups for Visual Basic
> ..NET related questions...
>
> microsoft.public.dotnet.languages.vb
> microsoft.public.dotnet.languages.vb.upgrade
> microsoft.public.dotnet.languages.vb.controls
> microsoft.public.dotnet.languages.vb.data
>
> And these for more general .NET questions
>
> microsoft.public.dotnet.general
> microsoft.public.vsnet.general
>
> Note: There are many other .NET newgroups (use the first three "fields"
> from the last two as templates when searching for them), but the above
> ones should get you started.
>
> Rick
>
>
>
>
>

Ken Halter

2005-08-03, 5:06 pm

"BBM" <bbm@bbmcompany.com> wrote in message
news:FCF728A6-1C94-46D8-BFC4-3F8FB88C04EE@microsoft.com...
> Sorry for mis-posting my question. It's so basic that I had to hunt for
> someplace to post it and I obviously picked the wrong place.
>
> PS. I wish the VB.Net folks would respond as quickly ;)
>
> Thanks.


They're too busy re-writing the world ;-)...

btw...

"It's so basic "

Should say....

It's so basic.net ;-)

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..


Rick Rothstein [MVP - Visual Basic]

2005-08-03, 5:06 pm

> Sorry for mis-posting my question. It's so basic that I had to hunt
for
> someplace to post it and I obviously picked the wrong place.


The question might have been "basic" (I assume no pun was intended by
you when you said that <g> ) but the syntax between the classic versions
of VB and VB.NET can be soooo different as to make asking VB.NET
questions here an exercise in futility. Our string Replace is a function
that returns a value (as opposed to a method of a String object) and
takes 3 arguments (the 3rd is optional with a default of a space
character), not the two you showed in your example. I'd guess there is
nothing a VB classic programmer could tell you that would be meaningful
in your .NET world regarding this (and many, many other) issues.

Rick


Paul Clement

2005-08-03, 5:06 pm

On Wed, 3 Aug 2005 08:13:13 -0700, "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote:

¤ "BBM" <bbm@bbmcompany.com> wrote in message
¤ news:FCF728A6-1C94-46D8-BFC4-3F8FB88C04EE@microsoft.com...
¤ > Sorry for mis-posting my question. It's so basic that I had to hunt for
¤ > someplace to post it and I obviously picked the wrong place.
¤ >
¤ > PS. I wish the VB.Net folks would respond as quickly ;)
¤ >
¤ > Thanks.
¤
¤ They're too busy re-writing the world ;-)...
¤

No, there's simply more questions to answer over there than there are here. ;-)


Paul
~~~~
Microsoft MVP (Visual Basic)
Paul Clement

2005-08-03, 5:06 pm

On Wed, 3 Aug 2005 07:49:20 -0700, BBM <bbm@bbmcompany.com> wrote:

¤ This is so bizarre I hesitate to post it, but I need to get this working.
¤
¤ My code looks like this...
¤
¤ Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _
¤ " WHERE Scenario =
¤ @Scenario"
¤ Dim cmdstr as String
¤
¤ cmdstr = cmdTestResourcesSel
¤ If history Then
¤ cmdstr.Replace("TResources", "TResourcesHistory")
¤ End If
¤ Dim cmdS As SqlCommand = New SqlCommand(cmdstr, cnTest)
¤
¤ History is true. Coming out of the "if" statement, cmdstr is unchanged.
¤ CommandText of the SQLCommand contains "TResources" not "TResourcesHistory"
¤ This same code template works in the same program in about a dozen other
¤ places. No exceptions thrown. I can do the replace on cmdstr in the
¤ command window while debugging the app and it works fine.
¤
¤ What's up with this???

The Replace method doesn't work that way because String classes are immutable. The function actually
returns the result of the operation just as Visual Basic 6.0 and VBScript does.

Also if you need more control you can use Microsoft.VisualBasic.Replace which offers the same
functionality as the Visual Basic 6.0 version.


Paul
~~~~
Microsoft MVP (Visual Basic)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com