formatting

VBScript: What is the simplest way to format a string?

陌路散爱 提交于 2019-12-17 06:54:31
问题 I have the following format: Value1 is {0} and Value2 is {1}. I need to replace the numbers in the brackets with strings. This is easily done in most languages using string.Format or something along those lines. How can I do this using only vbscript? I've tried: Replace (strFormat, "{0}", value1) Replace (strFormat, "{1}", value2) It does not work. Any solutions? 回答1: Replace (strFormat, "{0}", value1) Based on your code snip, I'm guessing you believe Replace mutates strFormat directly. It

VBScript: What is the simplest way to format a string?

北战南征 提交于 2019-12-17 06:53:02
问题 I have the following format: Value1 is {0} and Value2 is {1}. I need to replace the numbers in the brackets with strings. This is easily done in most languages using string.Format or something along those lines. How can I do this using only vbscript? I've tried: Replace (strFormat, "{0}", value1) Replace (strFormat, "{1}", value2) It does not work. Any solutions? 回答1: Replace (strFormat, "{0}", value1) Based on your code snip, I'm guessing you believe Replace mutates strFormat directly. It

Formatting timedelta objects [duplicate]

人盡茶涼 提交于 2019-12-17 05:03:31
问题 This question already has answers here : Format timedelta to string (22 answers) Closed 6 months ago . I have two datetime objects. I need to calculate the timedelta between them and then show the output in a specific format. Alpha_TimeObj = datetime.datetime(int(AlphaTime.strftime('%Y')), int(AlphaTime.strftime('%m')), int(AlphaTime.strftime('%d')), int(AlphaTime.strftime('%H')), int(AlphaTime.strftime('%M')), int(AlphaTime.strftime('%S'))) Beta_TimeObj = datetime.datetime(int(BetaTime

Changing date format to “%d/%m/%Y”

旧城冷巷雨未停 提交于 2019-12-17 04:31:35
问题 Would like to change the date format. My data frame is shown below and would like to change all the date formats to "%d/%m/%Y" . df: id bdate wdate ddate 1 09/09/09 12/10/09 2009-09-27 回答1: df$ddate <- format(as.Date(df$ddate), "%d/%m/%Y") 回答2: df$ddate<-strftime(df$ddate,"%d/%m/%Y") df$bdate<-strftime(strptime(df$bdate,"%d/%m/%y"),"%d/%m/%Y") df$wdate<-strftime(strptime(df$wdate,"%d/%m/%y"),"%d/%m/%Y") 回答3: Default R action is to treat strings as factors. Of course, an individual setup may

Format a number as 2.5K if a thousand or more, otherwise 900

故事扮演 提交于 2019-12-17 02:55:08
问题 I need to show a currency value in the format of 1K of equal to one thousand, or 1.1K, 1.2K, 1.9K etc, if its not an even thousands, otherwise if under a thousand, display normal 500, 100, 250 etc, using javascript to format the number? 回答1: Sounds like this should work for you: function kFormatter(num) { return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num) } console.log(kFormatter(1200)); // 1.2k console.log(kFormatter(-1200)); //

How to convert current date into string in java?

老子叫甜甜 提交于 2019-12-17 02:44:09
问题 How do I convert the current date into string in Java? 回答1: String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date()); 回答2: // GET DATE & TIME IN ANY FORMAT import java.util.Calendar; import java.text.SimpleDateFormat; public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; public static String now() { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); return sdf.format(cal.getTime()); } Taken from here 回答3: // On the

SQL Server Convert Varchar to Datetime

两盒软妹~` 提交于 2019-12-17 02:37:07
问题 I have this date format: 2011-09-28 18:01:00 (in varchar), and I want to convert it to datetime changing to this format 28-09-2011 18:01:00. How can I do it? 回答1: SELECT CONVERT(Datetime, '2011-09-28 18:01:00', 120) -- to convert it to Datetime SELECT CONVERT( VARCHAR(30), @date ,105) -- italian format [28-09-2011 18:01:00] + ' ' + SELECT CONVERT( VARCHAR(30), @date ,108 ) -- full date [with time/minutes/sec] 回答2: Like this DECLARE @date DATETIME SET @date = '2011-09-28 18:01:00' select

Rounding numbers in Objective-C

蹲街弑〆低调 提交于 2019-12-17 02:22:54
问题 I'm trying to do some number rounding and conversion to a string to enhance the output in an Objective-C program. I have a float value that I'd like to round to the nearest .5 and then use it to set the text on a label. For example: 1.4 would be a string of: 1.5 1.2 would be a string of: 1 0.2 would be a string of: 0 I've spent a while looking on Google for an answer but, being a noob with Objective-C, I'm not sure what to search for! So, I'd really appreciate a pointer in the right direction

Format a Go string without printing?

我与影子孤独终老i 提交于 2019-12-17 02:07:34
问题 Is there a simple way to format a string in Go without printing the string? I can do: bar := "bar" fmt.Printf("foo: %s", bar) But I want the formatted string returned rather than printed so I can manipulate it further. I could also do something like: s := "foo: " + bar But this becomes difficult to read when the format string is complex, and cumbersome when one or many of the parts aren't strings and have to be converted first, like i := 25 s := "foo: " + strconv.Itoa(i) Is there a simpler

Java output formatting for Strings

我的未来我决定 提交于 2019-12-17 01:01:20
问题 I was wondering if someone can show me how to use the format method for Java Strings. For instance If I want the width of all my output to be the same For instance, Suppose I always want my output to be the same Name = Bob Age = 27 Occupation = Student Status = Single In this example, all the output are neatly formatted under each other; How would I accomplish this with the format method. 回答1: EDIT: This is an extremely primitive answer but I can't delete it because it was accepted. See the