I'd like to build a URL using String.Format
String.Format(" http://server.com/page.aspx?id={0 }{1:\&optionalP arameter=0;&}",
id, optionalParam);
The idea is that I want to exclude the &optionalparamt er=value part of the
string when optionalParam is negative.
I've tried to place nothing after the semicolon blank but that outputs
(strange?) the minus sign to the url string.
The help in MSDN points to a description of VB6 format function and that
gives me no help (could microsoft pelase update this?).
Any help appreciated!
thanks,
mortb 14 1882
I do not think there is a direct way to do that.
You could, however, do something like:
string.Format(" http://server.com/page.aspx?id={0 }{1}"
, id
, 0x0 <= optionalParamet er
? string.Concat(" &optionalParame ter=", optionalParamet er.ToString())
: string.Empty);
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"mortb" <mortb1<noospam <@hotmail.com > wrote in message
news:OS******** ******@TK2MSFTN GP11.phx.gbl... I'd like to build a URL using String.Format String.Format(" http://server.com/page.aspx?id={0 }{1:\&optionalP arameter=0;&}", id, optionalParam); The idea is that I want to exclude the &optionalparamt er=value part of the string when optionalParam is negative. I've tried to place nothing after the semicolon blank but that outputs (strange?) the minus sign to the url string. The help in MSDN points to a description of VB6 format function and that gives me no help (could microsoft pelase update this?).
Any help appreciated! thanks, mortb
<"mortb" <mortb1<noospam <@hotmail.com >> wrote: I'd like to build a URL using String.Format String.Format(" http://server.com/page.aspx?id={0 }{1:\&optionalP arameter=0;&}", id, optionalParam); The idea is that I want to exclude the &optionalparamt er=value part of the string when optionalParam is negative. I've tried to place nothing after the semicolon blank but that outputs (strange?) the minus sign to the url string. The help in MSDN points to a description of VB6 format function and that gives me no help (could microsoft pelase update this?).
I must say, this is quite an odd way of going about formatting.
However, you can get it to work. Try this for the format string:
{1:'&optionalPa rameter='0;''}
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Dennis Myrén <de****@oslokb. no> wrote: I do not think there is a direct way to do that. You could, however, do something like: string.Format(" http://server.com/page.aspx?id={0 }{1}" , id , 0x0 <= optionalParamet er ? string.Concat(" &optionalParame ter=", optionalParamet er.ToString()) : string.Empty);
Note that a more readable (and entirely equivalent) way of writing the
last parameter would be:
optionalParamet er >= 0 ? "&optionalParam eter="+optional Parameter : ""
The C/C++-like habit of avoiding putting variables on the left hand
side of comparisons in order to avoid accidental assignment is
unnecessary in C# (aside from for booleans, where I find it's rare to
see "x==true" or "x==false" rather than just "x" or "!x").
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
I could not agree more!
/mortb
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Dennis Myrén <de****@oslokb. no> wrote: I do not think there is a direct way to do that. You could, however, do something like:
string.Format(" http://server.com/page.aspx?id={0 }{1}" , id , 0x0 <= optionalParamet er ? string.Concat(" &optionalParame ter=", optionalParamet er.ToString()) : string.Empty);
Note that a more readable (and entirely equivalent) way of writing the
last parameter would be:
optionalParamet er >= 0 ? "&optionalParam eter="+optional Parameter : ""
The C/C++-like habit of avoiding putting variables on the left hand
side of comparisons in order to avoid accidental assignment is
unnecessary in C# (aside from for booleans, where I find it's rare to
see "x==true" or "x==false" rather than just "x" or "!x").
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too I must say, this is quite an odd way of going about formatting. However, you can get it to work. Try this for the format string:
{1:'&optionalPa rameter='0;''}
Thank you!
cheers,
mortb
Jon Skeet wrote: Note that a more readable (and entirely equivalent) way of writing the last parameter would be: optionalParame ter >= 0 ? "&optionalParam eter="+optional Parameter : ""
Thank you for pointing that out for me.
I am very aware of that fact though.
This is coming down to a matter of favour of coding styles.
I personally like to place constants on the left
even if i could place them on the right side.
I think System.String.C oncat is prettier
than "manual" string concatenation using operator +.
That is why i always use that instead.
The only exception is when the strings concatenated is constant strings,
because then the compiler is free to optimize the statement by actually
concatenating them during compilation, and I do not think that is the case
with String.Concat.
This is the second time you are noticing me of the constants on the left
thing.
I interpret that as you do not want me to use that syntax in code posts.
I will try to avoid it from now on.
By the way, the {1:'&optionalPa rameter='0;''} solution was nice!
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Dennis Myrén <de****@oslokb. no> wrote: I do not think there is a direct way to do that. You could, however, do something like:
string.Format(" http://server.com/page.aspx?id={0 }{1}" , id , 0x0 <= optionalParamet er ? string.Concat(" &optionalParame ter=", optionalParamet er.ToString()) : string.Empty);
Note that a more readable (and entirely equivalent) way of writing the
last parameter would be:
optionalParamet er >= 0 ? "&optionalParam eter="+optional Parameter : ""
The C/C++-like habit of avoiding putting variables on the left hand
side of comparisons in order to avoid accidental assignment is
unnecessary in C# (aside from for booleans, where I find it's rare to
see "x==true" or "x==false" rather than just "x" or "!x").
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
I understand you are very grateful for me answering your question.(..... .)
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"mortb" <mortb1<noospam <@hotmail.com > wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. . I could not agree more! /mortb
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message news:MP******** *************** *@msnews.micros oft.com... Dennis Myrén <de****@oslokb. no> wrote: I do not think there is a direct way to do that. You could, however, do something like:
string.Format(" http://server.com/page.aspx?id={0 }{1}" , id , 0x0 <= optionalParamet er ? string.Concat(" &optionalParame ter=", optionalParamet er.ToString()) : string.Empty);
Note that a more readable (and entirely equivalent) way of writing the last parameter would be:
optionalParamet er >= 0 ? "&optionalParam eter="+optional Parameter : ""
The C/C++-like habit of avoiding putting variables on the left hand side of comparisons in order to avoid accidental assignment is unnecessary in C# (aside from for booleans, where I find it's rare to see "x==true" or "x==false" rather than just "x" or "!x").
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Dennis Myrén <de****@oslokb. no> wrote: Jon Skeet wrote:Note that a more readable (and entirely equivalent) way of writing the last parameter would be: optionalParame ter >= 0 ? "&optionalParam eter="+optional Parameter : "" Thank you for pointing that out for me. I am very aware of that fact though.
Goodo.
This is coming down to a matter of favour of coding styles. I personally like to place constants on the left even if i could place them on the right side.
Fair enough, although I think most people find it less readable that
way.
I think System.String.C oncat is prettier than "manual" string concatenation using operator +.
Again, I think most people would disagree with you in terms of
readability. That's entirely your prerogative though - I'm certainly
not going to try to tell you what *you* find more readable :)
That is why i always use that instead. The only exception is when the strings concatenated is constant strings, because then the compiler is free to optimize the statement by actually concatenating them during compilation, and I do not think that is the case with String.Concat.
Indeed.
This is the second time you are noticing me of the constants on the left thing. I interpret that as you do not want me to use that syntax in code posts. I will try to avoid it from now on.
Feel free to keep doing it - I wasn't sure whether you were just doing
it from C/C++ habits unnecessarily though. (I don't keep track of who
I've explained it to :) I'm certainly in no position to demand people
format their code in a particular way (although if they're asking me a
question it helps if they make it readable).
By the way, the {1:'&optionalPa rameter='0;''} solution was nice!
I'm not sure I'd actually use the word "nice" here - it's a solution
which is relatively hard to read, IMO, but it seems to be the way the
OP wanted to play things.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
But of course :)
But as I am not a big fan of writing hex values in my source I think parm <
0 is more readable.
It tells me more about what the intention was when I wrote the code and thus
it decreases the time to "re-understand" the code some seconds when I open
the file to fix some bugs.
cheers,
mortb
"Dennis Myrén" <de****@oslokb. no> wrote in message
news:gZ******** **********@news 4.e.nsc.no... I understand you are very grateful for me answering your question.(..... .) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Simon Brooke |
last post by:
I'm investigating a bug a customer has reported in our database
abstraction layer, and it's making me very unhappy.
Brief summary:
I have a database abstraction layer which is intended to mediate
between webapps and arbitrary database backends using JDBC. I am very
unwilling indeed to write special-case code for particular
databases. Our code has worked satisfactorily with many databases,
including many instances MS SQLServer 2000...
|
by: Jerry Harris |
last post by:
Hello,
After copying a database to a new computer, a header using the
=Format$ stops working. Instead of displaying the field, the report
prompts me to "Enter paramater value for Format$. Any input would be
appreciated.
TIA,
Jerry Harris
Western Kentucky University
|
by: James P. |
last post by:
Hello there,
I'd like to have my minutes convert to hours and minutes in Access
report in this format: hh:mm. For examples: 150 minutes converts to
2:30. I have this formula below used to work with my machine using
Access 2002 SP3.
=\60 & Format( Mod 60,"\:00")
However, if I run it on someone else's machine who has a newer
|
by: Danny Lesandrini |
last post by:
I'm using an Access database to drive a web site and the
colors of various table backgrounds are stored in Access.
I want users of the Access database to be able to select
colors for the site, but my mappings between named colors,
HEX values and the Long Integer values used in Access are
not jibbing. Anyone have a nice list laying around?
Danny J Lesandrini
dlesandrini@hotmail.com
|
by: Sebastian Santacroce |
last post by:
I'm trying to format datetime column in datagrid to a time
format rather than date. I'm using code:
Dim myGridTextBoxColumn As DataGridTextBoxColumn = New
DataGridTextBoxColumn()
myGridTextBoxColumn = CType(datagrid.TableStyles
(0).GridColumnStyles("StartDate"), DataGridTextBoxColumn)
myGridTextBoxColumn.Format="hh:mm:ss tt"
| |
by: Jason Kendall |
last post by:
How do I use a curly brace within a string passed to String.Format?
I want to pass a string that includes a curly brace, but that curly
brace is not being used to indicate a replacable format parameter.
Ex: Debug.Writeline(String.Format("{ts '{0:yyyy-MM-dd hh:mm}'}",
Date.Now)
Thanks.
-Jason Kendall
|
by: Jon Paal |
last post by:
need to apply a user defined date format:
Line 2064: retvalue = Format(Cdate(retvalue),"MM/dd/yyyy").ToString()
but get this error:
Line 2064: Reference to a non-shared member requires an object reference
what object reference is needed ?
|
by: Dixie |
last post by:
I am appending some new fields to a table in vba and when I append a number
field with is a byte, it does not inherit any format. I want it to be the
General Number format, but it is blank. I have tried to change the format
with the following code, but it does not work. What is wrong with this code
and how can I make that byte number field have the General Number format?
Call...
|
by: GTARDIO |
last post by:
Hello,
I use vb 6.0 to create an xml file. I use the microsoft XML V.5.0 reference.
After I create nodes, attributes etc. I use lDOMDoc.save "c:\temp\example.xml" and the xml file is saved in this path.
Everything is Ok when this file is opened with the internet explorer. But if opened as a text file, it is just one long line of text. Is there a way to
format this file to be shown in a cascade format. ?
Some XML files, when opened...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |