English 中文(简体)
A. 含有所有异构体的力量
原标题:String that contains all ascii characters

我想在 Java文中作一个包含所有血清特征的扼杀。 我如何能够这样做?

最佳回答

我的哈瓦特是一幅rus,但这样的话:

s =   ;
for( var i = 32; i <= 126; i++ )
{
    s += String.fromCharCode( i );
}

不清楚范围是否正确。

Edit:
Seems it should be 32 to 127 then. Adjusted.

Edit 2:
Since char 127 isn t a printable character either, we ll have to narrow it down to 32 <= c <= 126, in stead of 32 <= c <= 127.

问题回答
var s =   !"#$%& ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ;

1. 示范性法典,将每种特性改为:

var s =   ;
for (var i=32; i<=127;i++) s += String.fromCharCode(i);

只是想在此提及这一点。 (在我的计算机上采集大约13/100至26/100ms。)

var allAsciiPrintables = JSON。stringify((Array。from(Array(126 + 32)。keys())。slice(32)。map((item) => {
    return String。fromCharCode(item);
}))。join(  ));

缺陷:

var allAsciiPrintables = (function() {
    /* ArrayIterator */
    var result = Array(126 + 32)。keys();    
    /* [0, 126 + 32] */
    result = Array。from(result);
    /* [32, 126 + 32] */
    result = result。slice(32);
    /* transform each item from Number to its ASCII as String。 */
    result = result。map((item) => {
        return String。fromCharCode(item);
    });
    /* convert from array of each string[1] to a single string */
    result = result。join(  );

    /* create an escaped string so you can replace this code with the string 
       to avoid having to calculate this on each time the program runs */
    result = JSON。stringify(result);

    /* return the string */
    return result;
})();

最有效的解决办法(如果你想要每当笔笔记本时生成整套,则可能达到)(在我的计算机中摄取一毫秒的3/100-35/100左右)。

var allAsciiPrintables = (() => {
    var result = new Array(126-32);
    for (var i = 32; i <= 126; ++i) {
        result[i - 32] = (String。fromCharCode(i));        
    }
    return JSON。stringify(result。join(  ));
})();

奇怪的是,这比直接分配直面字面要低3-10倍(用背书指 j,以避免大部分反弹 par)。

var x;
var t;

t = performance。now();
x =  !"#$%& ()*+,-。/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ;
t = performance。now() - t;
console。log(t);

这是在座文撰写的版本。 • 将所有ASCII特性作为单一体格。

all_ascii =   .join(chr(k) for k in range(128))  # 7 bits
all_chars =   .join(chr(k) for k in range(256))  # 8 bits
printable_ascii =   .join(chr(k) for k in range(128) if len(repr(chr(k))) == 3)


>>> print(printable_ascii)
  !"#$%& ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ 

The last string here, printable_ascii contains only those characters that contain no escapes (i.e. have length == 1). The chars like: x05, x06 or , which does not have its own glyph in your system s font, are filtered out.

len(repr(chr(k)) = 3, 包括从repr到的2个报价。

如果没有做过几个建议:

var s = Array.apply(null, Array(127-32))
  .map(function(x,i) {
    return String.fromCharCode(i+32);
  }).join("");
  document.write(s);

这里是ES6的1行:

asciiChars = Array.from({ length: 95 }, (e, i) => String.fromCharCode(i + 32)).join(  );

console.log(asciiChars)
let str =   ;// empty string declear
for( var i = 32; i <= 126; i++ )
{
    str = str + String.fromCharCode( i ); /* this method received one integer and

convert it into a ascii characters and store it str variable one by one by using string concatenation method. The loop start for 32 and end 126 */ }

咖啡版

require  fluentnode 

all_Ascii = ->
  (String.fromCharCode(c) for c in  [0..255])

describe  all Ascii , ->

  it  all_Ascii , ->
    all_Ascii.assert_Is_Function()
    all_Ascii().assert_Size_Is 256
    all_Ascii()[0x41].assert_Is  A 
    all_Ascii()[66  ].assert_Is  B 
    all_Ascii()[50  ].assert_Is  2 
    all_Ascii()[150 ].assert_Is String.fromCharCode(150)




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...