Refactor - Replace With Constant String.Empty

Oct 17, 2011

I have the following line of code
Dim a As String = ""
And the Refactor suggests replacing the "" with String.Empty
It is a kind of Refactoring but why? Since I am a newbie in the future declarations of mine should I better use the String.Empty ?

View 5 Replies


ADVERTISEMENT

Create A Function That Replace The Apostrophe (') Into Empty String?

Nov 26, 2010

How to create a function that replace the apostrophe (') into empty string?

View 3 Replies

Nothing Equals String.Empty, Null Does Not Equal String.Empty?

Jun 28, 2010

This must've have been asked before but I couldn't locate it. In a mixed code project (VB and C#) we were debugging some old Visual Basic code where a statement as follows could be found:

If Request.Params("xxx") <> "" Then
'do something

I considered this a bug as Request.Params could be null, in which case the statement would've become false which wasn't the idea. So I thought. I just found out, -- probably for the tenth time and I will keep forgetting -- that the following two statements are not equal, while Nothing in VB should be equal to null in C# (thought I):

if(String.Empty == null) // always false
If String.Empty = Nothing Then ' always true

Should I dismiss this as a typical Microsoft backward compatibility effort, or should I consider this a huge error in the VB.NET compiler? Does anybody know the Microsoftean opinion on this oddity?

View 3 Replies

Get An Error On Guid.Empty "Constant Expression Is Required."

Sep 13, 2011

If I write the following inside my class,

<DefaultValue(Guid.Empty)> _
Public Property KeyValue() As Guid

I get an error on Guid.Empty "Constant expression is required."

What I'm trying to accomplish is to get rid of this line that shows up in the Designer file,

Me.TestUserControl1.KeyValue = New System.Guid("00000000-0000-0000-0000-000000000000")

I can avoid running the property's Set code with some conditionals on the Value sent when the form instances. I was just wondering if there's a way to deal with it similar to other data types.

View 4 Replies

Arrays - If Not String.Empty Ignoring Empty String

Aug 11, 2010

I have a array of strings and I am looping through them, but the string might be empty so I am trying this:

[Code]...

View 3 Replies

String.replace - Replace The New Format YYYY-MM-DD Back To YYYYMMDD In The Code

May 5, 2009

The file reads in parameters and two of the parameters used to be in Date Format YYYYMMDD but will now permanently be in format YYYY-MM-DD. This change, I believe, is stopping the import of the file from working. I would like to replace the new format YYYY-MM-DD back to YYYYMMDD in the code. If possible I'd also like to see some output so I know that the old format has been replaced with the new format. The code is below. I added the two rows with .replace code in green in expecting that to be enough but it is still not working.

Public
Sub Main()
Dim R1, O1, P1, C1, strDateFrom, strDateTo, strRunDate
As
String

[CODE]...

View 3 Replies

Use String As A VB Constant?

May 17, 2012

I have strMyColor = "Red".I would like to make lblMyLabel.BackColor to be red.Without using a variable the code would be this:

lblMyLabel.BackColor=Color.Red

I tried using the variable like this: lblMyLabel.backcolor="Color." & strMyColor

But the error is that a string can't be converted to System.Draw.Color. I understand that, as the string "Color.Red" is not the same as the VB constant Color.Red.Is there a way I can construct a valid vbConstant from a string?

View 10 Replies

Convert A String To A Constant String?

Jun 9, 2009

I have the following code...

Const ToAddress As String = username.Text & "url..."

which sets to ToAddress to be used in on my Net.Mail.MailMessage that is to be created with the following constructor

Dim mm As New Net.Mail.MailMessage(username.Text, ToAddress)

which takes in a string and a constant string. But I get an error here[url]...

View 6 Replies

String Must Be Literal. Not A Constant Or A Variable?

Jun 12, 2011

Public Class Form1
Private

[code].....

View 2 Replies

Public Constant Versus Private Constant?

Aug 13, 2011

When building a class library which contains many classes, all classes uses a lot of common constants and functions, what is the best to do:

1- Declare these constants and functions as public in a module.

2- In each class declare constants and functions used by individual class as private.

The first choice is good for easy and fast implementation, but re-using a class in a different project will require importing the module to the other project.The second choice require a lot of copy/paste for code snippet but a class can be re-used in different project easily.

View 3 Replies

Can't Convert Integer To String In Constant Expression

Mar 26, 2010

I'd like to understand why one type can't be converted to another type inside a constant expression.

View 13 Replies

Convert A String To Declared Public Constant

Jan 2, 2012

I have declared some constants as double in a Class

[Code]....

I'm tryingto figure out how I can get the text box to display the value of the constant with the same name? i.e 1.54186 in the example given

View 11 Replies

DLL Declaration Won't Accept Constant String Variable?

Apr 26, 2010

I'm making a call to my DLL file (prototyping 30+ functions), and want to be able to switch between different versions of the DLL quickly while in development. Thus, i want to replace the literal string constant that follows the "Lib" key word, with a variable string constant. In case there's any confusion in my use of the jargon. I am currently able to do this:

[Code]...

View 1 Replies

Forms :: Convert A String Variable To Constant

Feb 6, 2010

I am developing an application which initially allows the user to browse and select a save location. The selected path is assigned to a public variable which is used with concatenation to crate folder for saving user input data. How can I change the path string to a constant so the user can run the program again without having to run setup routine unless they want to change the save location?

View 1 Replies

VS 2005 Variable / Constant Name Held In String

Oct 13, 2011

suppose I have variables named A1, A2, A3 ... B1, B2, B3 ... Z97, Z98, Z99. I have a certain operation I want to do using each one in turn. I CAN write a line of code for every single variable, but this will get pretty tedious. I'd prefer it if I can make a function that takes the letter and the number as arguments. So, if it gets the arguments "E" and "10" it will perform the operation on variable E10. What is the syntax for this? say a simple operation such as: result = E10 * 3 Is the syntax any different if I use constants instead of variables?

View 3 Replies

.net - Show Constant String For The Color In Form Designer

Dec 16, 2010

I am working in .Net 2010 framework 2.0 I want to place the constant string for a color property in form designer like GradientBeginColor = MyColor in form designer.

View 1 Replies

Achieve CSS With Constant Values , Arithmetic And String Manipulation?

Mar 30, 2012

When developing ASP.NET websites (using VB.NET web forms) - a lot of my time is spend writing CSS files and they always seem to get messy (code duplication) and very long.

All I want to achieve is to be able to manipulate the CSS using VB.NET code in the following ways:

Use an integer variable to store my "golden" number 7 and use that for width, padding, margin etc where needed
Use string variables to store my "golden" hex color codes e.g. "#44C5F2" and use them for color, background-color, border-color etc. where needed Use an integer variable to set the height of an element and have four child elements each with height: mynum / 4

I just want to use basic VB.net number and string manipulation in order to create a CSS file on the fly.

I understand that the end product - the CSS file shouldn't change much - it should at most change on a daily basis otherwise caching couldn't be used.[code]...

View 3 Replies

Visual Studio Does Not Flag Unterminated String Constant?

May 25, 2010

I noticed that if I leave off the terminating double quote for a string constant in Visual Studio 2010, there is no error or even a warning, i.e.

Dim foo as String = "hi

However, the continuous integration tool we are using flags an error:

error BC30648: String constants must end with a double quote.

Is there some language rule in VB.Net that makes a terminating double quote optional "sometimes"? Is there some setting in Visual Studio that will make it flag this as an error, so I can avoid "breaking the build" in this way?

View 3 Replies

Localizing Multi-lined String As One Constant In Resource File

Jan 4, 2010

I have a multi-lined string message that needs to be added to the Resources.resx file of the project. Currently I'm achieving this some thing like this MessageBox(My.Resources.MyMsg1 & vbNewLine & My.Resources.MyMsg2 ). This works.However I'd like to have the entire message in one resource string rather than adding two resources strings to the Resources.resx file.I've tried using' but no luck..message displays as "My message.Rest of the message".I've also tried manually adding a new line in the Resources.resx file. ( by doing "My message.<Shift+Enter>Rest of the message" But message is adding an additional space before the message in the second line.

View 8 Replies

Replace String - Replaced One Blank Line And " Replace By "

Apr 7, 2009

Suppose i have two strings which is given below.

CODE:

Where ever i find , it should be replaced one blank line and " replace by "

When i migrated the data from MYSQL to SQL Server 2005, i found few problem in one of the column. In MYSQL indicates as new line and " indicates as ".

View 7 Replies

Why STRING Does Not Have A Parameterless Constructor To Create An Empty String

Feb 4, 2012

I was trying to call a method using Reflection on a method that has a STRING parameter.However a STRING does not have a parameterless constructor.So instead of something like.>>

Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1

[code].....

View 15 Replies

[2008] Finding The First Empty String In A String Array?

Mar 2, 2009

i have a string array that i want to output to a text file. the array size is 10000. i fill the array starting from 0 with some strings. at the end, i only want to show the array from index 256 to the last array that is not empty (for eg. if the array is filled with data from 0 to 2000, i only want the text file to show the data from 256 to 2000 and ignore the remaining strings). Is there any function to do this?t i use is shown below

Dim myArray(10000) as string
Dim strArray As New System.IO.StreamWriter("c:List.txt")
strArray.WriteLine("{0,10}{1,30}", "Index", "Symbol")

[code].....

View 8 Replies

Options To The User In A Menu - Create Sub-string - Replace A Word In The String

Feb 28, 2010

Problem: Your task is to take input from the user in string and give the following options to the user in a menu.

1- Find a String
2- Create sub-string
3- Erase a portion of a sting
4- Replace a word in the string
5- Count number of words and characters in the string without spaces.
6- Capitalize first character of each new sentence and convert the rest
of the characters to lower case.
7- Sort all the words in alphabetical order. (Use Bubble sort algorithm to perform sorting).

To perform all the above mentioned tasks you can only use pointers. Create a function to perform every task.

View 1 Replies

Finding The First Empty String In String Array?

Mar 2, 2009

i have a string array that i want to output to a text file. the array size is 10000. i fill the array starting from 0 with some strings. at the end, i only want to show the array from index 256 to the last array that is not empty (for eg. if the array is filled with data from 0 to 2000, i only want the text file to show the data from 256 to 2000 and ignore the remaining strings). Is there any function to do this? i am using visual basic express 2008. The code that i use is shown below

[Code]...

View 2 Replies

Testing String Value Of Nothing Is Equivalent To String.Empty

Feb 24, 2010

I have a nullable database field of type varchar. I am writing a unit test for a service method that retrieves the value of this field. The service method uses a custom DAL that returns a value of String.Empty if the database field is Null (this is desired behaviour).

[Code]...

View 3 Replies

When String Variable Was Empty String First One Returns 'nothing'

Oct 2, 2009

just found out that replace(string does not do the same as string.replace when my string variable was an empty str the first one returns "nothing" and the second returns an empty string (as expected).just sloppy coding anyhow, it was a function that was converted from classic asp and never rewritten properly. [code]

View 1 Replies

Replace Letter In A Changing String With Another String...

Sep 16, 2011

i am making a l337 speak generator..Lets say I input bob12321 (although i can input anything)I would like to make the program replace the "b" with either [code]How would i do that... I tried string.replace - but it says character A cannot be turned into long (on a seperate word)[code]

View 6 Replies

Search For A String And Replace With New String Program?

Apr 27, 2011

I have a non standard text file, ie its not delimted etc, its pretty much free flowing. What I want to do is to search for a specifc string eg. "xyz123" and then replace it with what a user types into a text box, lets call the text box and its contents "txtreplace".

I am trying to replicate a find and replace function essentially, but will need to tailor it later on down the line, but this will be a starting point.

View 4 Replies

Why Can't Do String.Replace() On A IO.File.ReadAllText() String

Jul 11, 2009

I am using System.IO.FIle.ReadAllText() to get the contents of some template files that I created for email content. Then I want to do a Replace on certain tokens within the files so I can add dynamic content to the template.Here is the code I have, it seems to me like it should work just fine...

Dim confirmUrl As String = Request.ApplicationPath & "?v=" & reg.AuthKey
Dim text As String = IO.File.ReadAllText( _
ConfigurationManager.AppSettings("sign_up_confirm_email_text").Replace("~", _

[code].....

For some reason I cannot get the %%LINK%% and %%NAME%% Replace() calls to work properly. I checked to see if it was encoding-related, so I made each file UTF-8. And also used the forced encoding overload of ReadAllText(String, Encoding) and still no dice.

View 1 Replies

C# - Refactor Data Contracts In WCF Services?

Feb 11, 2010

We have lots of WCF services that are only used by our own code; the code that uses them is mostly in the same solutions files that contains the services.

However they do not use a shared assembly for the contracts, so each time a data contract is change the reference to the service has to be updated by hand in all projects that use the service. (Then the code needs to be fixed up by hand)

So how do I do a simple refactoring like renamed a data item in a data contract?

Is there a way to update all references to services in a single solution with one command, rather then having to click on each reference in each project?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved