Generally, splicing a string is very common in programming , Let's make a summary :

What is a place holder ? A place holder is to occupy a fixed position first , Waiting for you to add symbols to it .

1.Java How to deal with it :

package com.amos;
import java.text.MessageFormat;
/**
* Created by amosli on 14-7-24.
*/
public class Test { public static void main(String args[]) { // Piece together string Common methods
String name="amosli";
// Method 1:
String result = "hello,"+name;
System.out.println(result);//hello,amosli // Method 2:
result = "hello,".concat(name);
System.out.println(result);//hello,amosli // Method 3:
result = String.format("%d%s", 200, " element ");
System.out.println(result);//200 element // Method 4:
result = MessageFormat.format("hi,{0},I am {1}", "Jack", "Amosli");
System.out.println(result);//hi,Jack,I am Amosli } }

notes :

Method one should be the most used , Use it directly + No. connector ;

Method 2 Use String class concat() Method to connect , Follow + It's very similar ;

Method 3 . Four Using a place holder , Method 3 uses String.format() Method , It should be noted that the character string should be used to represent the content to be replaced %s, The number is usually %d To said .

Method 4 is used directly {n}, among n Represent the order of parameters for numbers , This and C# It's very similar in .

2.C# Placeholder in

static void Main()
{
string c="hello,amosli";
string m=String.Format(“{}”,c); // String format output
Console.WriteLine(m); //hello,amosli
}
 Here are some commonly used formatted identifiers :
Letter meaning
C or c Currency Currency format
D or d Decimal Decimal format ( Decimal integer , Do not mix .Net Of Decimal Data types are confused )
E or e Exponent Exponential format
F or f Fixed point Fixed precision format
G or g General Common formats
N or n Separate thousands of digits with commas , such as 1234 Will be turned into 1,
P or p Percentage Percent symbol format
R or r Round-trip Roundness ( For floating point numbers only ) Ensure that a number can be converted back to the same number after it is converted into a string
X or x Hex 16 Base format
Examples are as follows ( see cs_6.cs)
static void Main()
{
int i=;
Console.WriteLine("{0:C}",i); // currency
Console.WriteLine("{0:D}",i); // Decimal number
Console.WriteLine("{0:E}",i); // Science and Technology Law
Console.WriteLine("{0:F}",i); // floating-point number
Console.WriteLine("{0:G}",i); //G or g General Common formats
Console.WriteLine("{0:N}",i); //N or n Separate thousands of digits with commas
}

notes : If you use @ Symbol . He'll ignore all the escape . That is to say {1} What's the point {1} Instead of identifying the placeholder , Here we need to pay attention to . namely "@{1}" This type will not be recognized as a placeholder .


3.C Placeholder in

C Format placeholders in languages :
%a,%A Read in a floating point value ( only C99 It works )
%c Read in a character
%d Read in decimal integers
%i Read in decimal , octal , Hexadecimal integer
%o Read in octal integers
%x,%X Read in hexadecimal integers
%s Read in a string , In case of space 、 End with tab or newline .
%f,%F,%e,%E,%g,%G It's used to enter real numbers , You can enter it in decimal or exponential form .
%p Read in a pointer
%u Read in an unsigned decimal integer
%n The number of equivalent characters of the value read so far
%[] Scan character sets
%% read % Symbol Example of format input and output
scanf("%d,%d,%d",&a,&b,&c); // Enter three integers from the keyboard , Separate with commas
scanf("%c", &s); // Enter a character from the keyboard
scanf("%f", &f); // Enter a floating-point data from the keyboard printf("%d\n",a); // Output an integer
printf("%f\n",b); // Output a floating point number
printf("%s\n",c); // Output a character

Basically, we can see that the three are very similar ,Java and C# It's basically copying C Linguistic .

Reference resources :

1.http://baike.baidu.com/view/873819.htm?fr=aladdin

2.http://www.cnblogs.com/fumj/articles/2380290.html

Java C# C More related articles on language placeholders

  1. JAVA Modifiers in language

    JAVA Modifiers in language -----------------------------------------------01--------------------------------------- ...

  2. Java Replace the placeholder in the string

    In development , There will be dynamic configuration strings with some of the characters , How to use placeholders in characters , And in the code dynamic replacement of placeholders to achieve dynamic configuration string ! 1. When defining a string , Again string File add string : Be careful ! Remember to add these to the character file : ...

  3. Swift3.0 The language tutorial uses the placeholder format to create and initialize strings

    Swift3.0 The language tutorial uses the placeholder format to create and initialize strings Swift3.0 The language tutorial uses the placeholder format to create and initialize strings. There are placeholders in many programming languages , A place holder is a place for the specified content . This function is generally used by developers ...

  4. 【 Placeholder replacement 】 Replace String Place holder flag bit in {placeholder}

    summary Placeholder replacement , The placeholder is represented by :{placeholder}; Example : Replace with the following {xxx} The content in the placeholder " name :{name}, Age :{age}, School :{school}" Two types are available ...

  5. Android programming resource file string The use of placeholders in

    Here's a detailed introduction to the use of placeholders , Put it into practice , It can simplify the layout file , Reduce string resources . 1. Use in resource files . Open... In the resource file strings.xml file , Editing . As shown in the figure below : chart   1.0 2. ...

  6. spring Of PropertyPlaceholderConfigurer How to access the read property (java access , No xml The place holder in ) And applications of this kind

    One .1. The application of placeholders :(@Autowired Annotation mode , No need to establish set And get The method ,xml I don't need to write any more ) http://www.cnblogs.com/susuyu/archive/2012/0 ...

  7. Java in Void Testing and personal understanding of placeholders

    Java Yes Void The description of the class is :Void Class is a non instantiatable placeholder class , It maintains a right to represent Java keyword void Of Class References to objects . It stands for :  Representing the main Java type voi ...

  8. hibernate Query statement hql Placeholder in ? Parameters and named parameters :name The way of setting value is confused

    Post the exception first Struts has detected an unhandled exception: Messages: Position beyond number of declared ordin ...

  9. [ turn ]scala and RDD Placeholder in "_"

    1. wildcard . similar Java Medium *. Such as :import scala.math._ 2. As a whole .:_*, Tell the compiler that you want to treat a parameter as a sequence of parameters ! for example val s = sum(1 to 5:_*) Will be ...

Random recommendation

  1. use CSS Hide page elements

    use CSS There are many ways to hide page elements . You can take opacity Set to 0 take visibility Set to hidden take display Set to none take position Set to absolute ...

  2. iOS 9/10 Compulsory use https Access the network , Using a third party SDK The application needs configuration information

    2017 year 01 month 01 Apple will ban the use of http To access the network . I picked up some resources on the Internet , There are solutions , But they are not sure whether they can pass the audit , After all, practice is the only test of truth . In the future, if the launch is successful , Share again . If we should ...

  3. Redis Cache of Set Use

    stay Redis in , We can Set Type as a character set without sorting , and List Same type , We can also add data values of this type . Delete or determine whether an element exists, etc . It should be noted that , The time complexity of these operations is O(1), ...

  4. mongodb tip-2

    1.or The format of the query : var condition = {$or:[{field:1},{field:2}]} 2. String storage date can also be used $gt $gte $lt $lte Direct comparison var cond ...

  5. Openjudge- Introduction to computation (A)- Chicken and rabbit in the same cage

    Describe a cage containing chickens and rabbits ( Chicken has 2 One foot , The rabbit has 4 One foot , No exceptions ). We already know the total number of feet in the cage a, Ask how many animals there are in the cage at least , How many animals are there at most 1 Row is the number of groups of test data n, Follow behind n Line input . Number of tests per group ...

  6. Windows The principle and application of multithreading programming under the environment of reading notes (2)———— Object oriented technology

    Object oriented technology is learning C++ What you need to focus on , Because I think my foundation is fairly good , This chapter is just a rough read , Don't take too many notes here .

  7. python Of socket analysis

    1. Realize one-to-one communication (1). The server code is as follows : import socket server = socket.socket() server.bind(("localhost" ...

  8. MobX Study

    Resource pooling posts : https://github.com/mobxjs/awesome-mobx/blob/master/README-CN.md Chinese document : http://cn.mobx.js.org/ ...

  9. [katalon] Page switching

    UI Automatic testing process will involve the need to switch multiple pages , For example, click a button to jump to a new page , the latter A After the site submits the information ,B Site audit . Katalon Although controlling multiple browsers is not supported , But support processing tab Switch . The core approach is to use ...

  10. caffe test mnist problem -error while loading shared libraries

    Problem description build/examples/mnist/convert_mnist_data.bin: error while loading shared libraries: libcudart.so ...