how to create a string like regex

user2809386

i am new in C# language, i am trying to create a new desktop app.

but i am confuse to create a string like this..

private string getResult(int x){
    string results = "";

    return results  
}

so when i use getResult(1), it will return 0001

if i use getResults(111), it will return 0111

if i use getResults(10), it will return 0010.

something like this, i am confuse to create a string like this.

Erik Šťastný

You can simple use ToString with parameter:

private string getResult(int x)
{
    return x.ToString("0000"); 
}

from @Dmitry Bychenko :

You can also use "D4" as parameter instead of "0000" with same results.

This solution also works with negative numbers instead of PadLeft method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to create a string like "?, ?, ?, ?, ?, ?, ? " in Scala?

how create regex pattern for this string

Regex for path like string

How to create a Regex to find exact String length?

How to create a regex for -90 to -90 string acceptance?

How to create ' inside a string wrapped like 'this is my string'

How to search/find special characters like &, < or > in the string with regex using Python

How to generate a regex code for string like this "12A13":

How to perform regex-like search in Elasticsearch on a string not analyzed

How to make regex if string contains comma(,) space, and other characters like (

How to express cpp-like string with regex (lexical analysis)

How can I grep for a string containing regex metacharacters like $ and '?

How to create a Google Like Text Snippet from String in Python?

How to Create a TypeScript like String Literal Union type in C#

How to create a tables with variable length with string-like keys in lua

how to create List<UserModel> by string name like "UserModel"

Create regex of string

Regex to extract and parse an array like string in string

How can I create union-like or enum-like behaviour from string constants in TypeScript?

How to create a layout like this?

How to create slider like this?

How to create button like this

How to write Regex for pattern like a series of Number and String pair separated by Space. Pattern -> n <space> string

How to create a regex that would include anything after a string

How can I create a regex validation expression to allow this string?

Any suggestions how to create Regex for this in java for String.replaceAll()?

How to create regex to match a string that contains only hexadecimal numbers and arrows?

PHP Regex create something like liquid tags

How do I create a regex that matches (p,s) precision and scale like the SQL decimal type?