java中的佔位符

2021-08-02 10:04:25 字數 763 閱讀 4403

int year=2017;

int month=6;

int day=1;

string str=string.format("今天是%d年%d月%d日,祝大家兒童節快樂!!!",

year, month, day);

**中的string.format方法,用來使用佔位符拼接字串資料,具有型別效果的還有用於列印的:

system.out.printf("format string",  object...args)

其中的 %d 就表示乙個十進位制整數字置,這個位置會由後面引數補充後組成新的字串

以下是所有的佔位符及簡要說明:

%s 字串

%c 字元

%d 整數(十進位制)

%x 整數(十六進製制)

%o 整數(八進位制)

%f 浮點型(十進位制)

%a 浮點型(十六進製制)

%e 指數型別9.38e+5

%g 通用浮點型別(f和e型別中較短的)

%n 換行\r\n

%% 百分號%

%tf 日期2017-05-09

%tt 時間08:52:59

%ta 星期一

%tz 區時cts

%tz 區時+0800

%ty 年份2017

%ty 年份17

%tm 月份05

%td 日期09

%th 小時08

%tm 分鐘52

%ts 秒鐘59

%tl 毫秒999

java中佔位符的使用

二話不說,先上 package com.string.format public class stringformat 拼接最後會多出個逗號,擷取 sqls sqls.substring 0,sqls.length 1 format第乙個sql引數為目標字串,tablename,tablename2...

OC中的佔位符

objective c物件,印有字串返回descriptionwithlocale 如果於的話,或描述相反.cftyperef工作物件,返回的結果的cfcopydescription功能 為 字元 d,d,i 為32位整型數 int u,u 為32位無符號整型數 unsigned int hi 為有...

python中的佔位符

python中容易被忽略的小知識點 python中佔位符 在輸出的地方預定的符號 1.d 整數佔位符 d只能佔位整數,即使是原數字為浮點數他也會強制轉換變成整數。2.f 浮點數佔位符 f只能佔位浮點數,xf 則是精確至小數點後x位。3.s 字串佔位符 s佔位字串,應用最多。age int input...