精华内容
下载资源
问答
  • System.out.println(java.util.Arrays .toString(textToNumericFormatV6(src))); } private static final int INADDR4SZ = 4; private static final int INADDR16SZ = 16; private static final int INT16SZ = 2; ...

    /*

    * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.

    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

    *

    * This code is free software; you can redistribute it and/or modify it

    * under the terms of the GNU General Public License version 2 only, as

    * published by the Free Software Foundation. Oracle designates this

    * particular file as subject to the "Classpath" exception as provided

    * by Oracle in the LICENSE file that accompanied this code.

    *

    * This code is distributed in the hope that it will be useful, but WITHOUT

    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

    * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

    * version 2 for more details (a copy is included in the LICENSE file that

    * accompanied this code).

    *

    * You should have received a copy of the GNU General Public License version

    * 2 along with this work; if not, write to the Free Software Foundation,

    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

    *

    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA

    * or visit www.oracle.com if you need additional information or have any

    * questions.

    */

    //package com.nowjava;

    public class Main {

    /* from

    时 代 J a v a - nowjava.com*/

    public static void main(String[] argv) throws Exception {

    String src = "nowjava.com";

    System.out.println(java.util.Arrays

    .toString(textToNumericFormatV6(src)));

    }

    private static final int INADDR4SZ = 4;

    private static final int INADDR16SZ = 16;

    private static final int INT16SZ = 2;

    public static byte[] textToNumericFormatV6(String src) {

    // Shortest valid string is "::", hence at least 2 chars

    /**

    来 自 时 代 J a v a

    **/

    if (src.length() < 2) {

    return null;

    }

    int colonp;

    char ch;

    boolean saw_xdigit;

    int val;

    char[] srcb = src.toCharArray();

    byte[] dst = new byte[INADDR16SZ];

    int srcb_length = srcb.length;

    int pc = src.indexOf('%');

    if (pc == srcb_length - 1) {

    return null;

    }

    if (pc != -1) {

    srcb_length = pc;

    }

    colonp = -1;

    int i = 0, j = 0;

    /* Leading :: requires some special handling. */

    if (srcb[i] == ':')

    if (srcb[++i] != ':')

    return null;

    int curtok = i;

    saw_xdigit = false;

    val = 0;

    while (i < srcb_length) {

    ch = srcb[i++];

    int chval = Character.digit(ch, 16);

    if (chval != -1) {

    val <<= 4;

    val |= chval;

    if (val > 0xffff)

    return null;

    saw_xdigit = true;

    continue;

    }

    if (ch == ':') {

    curtok = i;

    if (!saw_xdigit) {

    if (colonp != -1)

    return null;

    colonp = j;

    continue;

    } else if (i == srcb_length) {

    return null;

    }

    if (j + INT16SZ > INADDR16SZ)

    return null;

    dst[j++] = (byte) ((val >> 8) & 0xff);

    dst[j++] = (byte) (val & 0xff);

    saw_xdigit = false;

    val = 0;

    continue;

    }

    if (ch == '.' && ((j + INADDR4SZ) <= INADDR16SZ)) {

    String ia4 = src.substring(curtok, srcb_length);

    /* check this IPv4 address has 3 dots, ie. A.B.C.D */

    int dot_count = 0, index = 0;

    while ((index = ia4.indexOf('.', index)) != -1) {

    dot_count++;

    index++;

    }

    if (dot_count != 3) {

    return null;

    }

    byte[] v4addr = textToNumericFormatV4(ia4);

    if (v4addr == null) {

    return null;

    }

    for (int k = 0; k < INADDR4SZ; k++) {

    dst[j++] = v4addr[k];

    }

    saw_xdigit = false;

    break; /* '\0' was seen by inet_pton4(). */

    }

    return null;

    }

    if (saw_xdigit) {

    if (j + INT16SZ > INADDR16SZ)

    return null;

    dst[j++] = (byte) ((val >> 8) & 0xff);

    dst[j++] = (byte) (val & 0xff);

    }

    if (colonp != -1) {

    int n = j - colonp;

    if (j == INADDR16SZ)

    return null;

    for (i = 1; i <= n; i++) {

    dst[INADDR16SZ - i] = dst[colonp + n - i];

    dst[colonp + n - i] = 0;

    }

    j = INADDR16SZ;

    }

    if (j != INADDR16SZ)

    return null;

    byte[] newdst = convertFromIPv4MappedAddress(dst);

    if (newdst != null) {

    return newdst;

    } else {

    return dst;

    }

    }

    @SuppressWarnings("fallthrough")

    public static byte[] textToNumericFormatV4(String src) {

    byte[] res = new byte[INADDR4SZ];

    long tmpValue = 0;

    int currByte = 0;

    boolean newOctet = true;

    int len = src.length();

    if (len == 0 || len > 15) {

    return null;

    }

    /*

    * When only one part is given, the value is stored directly in

    * the network address without any byte rearrangement.

    *

    * When a two part address is supplied, the last part is

    * interpreted as a 24-bit quantity and placed in the right

    * most three bytes of the network address. This makes the

    * two part address format convenient for specifying Class A

    * network addresses as net.host.

    *

    * When a three part address is specified, the last part is

    * interpreted as a 16-bit quantity and placed in the right

    * most two bytes of the network address. This makes the

    * three part address format convenient for specifying

    * Class B net- work addresses as 128.net.host.

    *

    * When four parts are specified, each is interpreted as a

    * byte of data and assigned, from left to right, to the

    * four bytes of an IPv4 address.

    *

    * We determine and parse the leading parts, if any, as single

    * byte values in one pass directly into the resulting byte[],

    * then the remainder is treated as a 8-to-32-bit entity and

    * translated into the remaining bytes in the array.

    */

    for (int i = 0; i < len; i++) {

    char c = src.charAt(i);

    if (c == '.') {

    if (newOctet || tmpValue < 0 || tmpValue > 0xff

    || currByte == 3) {

    return null;

    }

    res[currByte++] = (byte) (tmpValue & 0xff);

    tmpValue = 0;

    newOctet = true;

    } else {

    int digit = Character.digit(c, 10);

    if (digit < 0) {

    return null;

    }

    tmpValue *= 10;

    tmpValue += digit;

    newOctet = false;

    }

    }

    if (newOctet || tmpValue < 0

    || tmpValue >= (1L << ((4 - currByte) * 8))) {

    return null;

    }

    switch (currByte) {

    case 0:

    res[0] = (byte) ((tmpValue >> 24) & 0xff);

    /**代码未完, 请加载全部代码(NowJava.com).**/

    展开全文
  • 展开全部toString()方法转换...JAVA的整型与字符串相互转换1、将字串 String 转换成整数 int1). int i = Integer.parseInt([String]); 或i = Integer.parseInt([String],[int radix]...

    展开全部

    toString()方法转换32313133353236313431303231363533e4b893e5b19e31333365633863成字符串。

    JAVA的整型与字符串相互转换

    1、将字串 String 转换成整数 int

    1). int i = Integer.parseInt([String]); 或

    i = Integer.parseInt([String],[int radix]);

    2). int i = Integer.valueOf(my_str).intValue();

    注: 字串转成 Double, Float, Long 的方法大同小异.

    2、将整数 int 转换成字串 String

    1.) String s = String.valueOf(i);

    2.) String s = Integer.toString(i);

    3.) String s = "" + i;

    注: Double, Float, Long 转成字串的方法大同小异.

    Java数据类型转换 ynniebo :这是一个例子,说的是JAVA中数据数型的转换.供大家学习引

    package cn.com.lwkj.erts.reGISter;

    import java.sql.Date;

    public class TypeChange {

    public TypeChange() {

    }

    //change the string type to the int type

    public static int stringToInt(String intstr)

    {

    Integer integer;

    integer = Integer.valueOf(intstr);

    return integer.intValue();

    }

    //change int type to the string type

    public static String intToString(int value)

    {

    Integer integer = new Integer(value);

    return integer.toString();

    }

    //change the string type to the float type

    public static float stringToFloat(String floatstr)

    {

    Float floatee;

    floatee = Float.valueOf(floatstr);

    return floatee.floatValue();

    }

    //change the float type to the string type

    public static String floatToString(float value)

    {

    Float floatee = new Float(value);

    return floatee.toString();

    }

    //change the string type to the sqlDate type

    public static java.sql.Date stringToDate(String dateStr)

    {

    return java.sql.Date.valueOf(dateStr);

    }

    //change the sqlDate type to the string type

    public static String dateToString(java.sql.Date datee)

    {

    return datee.toString();

    }

    public static void main(String[] args)

    {

    java.sql.Date day ;

    day = TypeChange.stringToDate("2003-11-3");

    String strday = TypeChange.dateToString(day);

    System.out.println(strday);

    }

    }

    JAVA中常用数据类型转换函数

    string->byte

    Byte static byte parseByte(String s)

    byte->string

    Byte static String toString(byte b)

    char->string

    Character static String to String (char c)

    string->Short

    Short static Short parseShort(String s)

    Short->String

    Short static String toString(Short s)

    String->Integer

    Integer static int parseInt(String s)

    Integer->String

    Integer static String tostring(int i)

    String->Long

    Long static long parseLong(String s)

    Long->String

    Long static String toString(Long i)

    String->Float

    Float static float parseFloat(String s)

    Float->String

    Float static String toString(float f)

    String->Double

    Double static double parseDouble(String s)

    Double->String

    Double static String toString(Double d)

    展开全文
  • import java.util.EnumMap;import java.util.HashMap;import java.util.Map;/*** This class transfers an integer number into a string :* * {@code* // an example :* NumberText ns = NumberText.getInstance(.....

    import java.util.EnumMap;

    import java.util.HashMap;

    import java.util.Map;

    /*** This class transfers an integer number into a string :

    *

    *

    {@code* // an example :

    * NumberText ns = NumberText.getInstance(NumberText.Lang.English);

    * ns.getText(123) // one hundred and twenty-three

    * ns.getOrdinalText(320) // three hundred and twentieth

    * }

    *

    * @date 09/02/2012

    *@authorna.shi.wu.you (raistlic@gmail.com)*/

    public abstract class NumberText {

    /*----------------------------------------------------------------------------

    * not designed to be inherented outside this file

    * no public constructors provided, -- use factory method

    ---------------------------------------------------------------------------*/

    private NumberText() {}

    /*** Transfers an integer number into a String, specifically in which language

    * depends on the implementation.

    *

    * e.g. in English,

    *

    * 100 -> one hundred

    *

    * -976083854 -> minus nine hundred and seventy-six million and eighty-three

    * thousand eight hundred and fifty-four

    *

    *@paramnumber the integer number to be transfered

    *@returnthe result String*/

    public abstract String getText(long number);

    /*** Transfers an integer number into a String of its ordinal representation,

    * specifically in which language depends on the implementation.

    *

    * e.g. in English,

    *

    * 100 -> one hundredth

    *

    * 8331125 -> eight million three hundred and thirty-one thousand one

    * hundred and twenty-fifth

    *

    *@paramnumber the integer number to be transfered

    *@returnthe result String*/

    public abstract String getOrdinalText(long number);

    /*** This enumeration type is typically named under a natural language

    * name, and is to mark a specific implementation name; it is used as an

    * argument to call the factory method

    * {@linkNumberText#getInstance(NumberText.Lang)}.*/

    public static enum Lang {

    English,

    EnglishWithCleanSpaceOnly,

    ChineseSimplified,

    ChineseTraditional,

    ;

    }

    /*** Exports a {@codeNumberText} implementation instance, based on a natural

    * language argument. {@seeLang}

    *

    *@paramlang

    *@returna NumberText instance.*/

    public static NumberText getInstance(Lang lang) {

    if( lang == null ) throw new NullPointerException();

    NumberText result = null;

    synchronized(_InstancePool) {

    result = _InstancePool.get(lang);

    if( result == null ) {

    switch(lang) {

    case English :

    result = new NumberTextEnglish();

    break;

    case EnglishWithCleanSpaceOnly :

    result = new NumberTextEnglishCleanSpaceOnly();

    break;

    case ChineseSimplified :

    result = new NumberTextChinese(NumberTextChinese.Type.Simplified);

    break;

    case ChineseTraditional :

    result = new NumberTextChinese(NumberTextChinese.Type.Traditional);

    break;

    default : throw new UnsupportedOperationException(

    "Language not supported yet : " + lang);

    }

    _InstancePool.put(lang, result);

    }

    }

    return result;

    }

    private static final Map _InstancePool =

    new EnumMap(Lang.class);

    private static boolean checkNumber(String number) {

    return number != null && number.matches("[0-9]+");

    }

    /*----------------------------------------------------------------------------

    * English Implementation

    ---------------------------------------------------------------------------*/

    private static class NumberTextEnglish extends NumberText {

    static enum Connect {

    Minus ("minus"),

    Hundred ("hundred"),

    And ("and"),

    AfterMinus (" "),

    AfterNumber (" "),

    AfterPower (" "),

    AfterHundred (" "),

    AfterAnd (" "),

    AfterTen ("-"),

    ;

    final String display;

    Connect(String display) { this.display = display; }

    private static boolean isConnect(char c) {

    return c == ' ' || c == '-';

    }

    }

    static enum Power {

    Thousand ("thousand"), //10 ^ 3 Million ("million"), //10 ^ 6 Billion ("billion"), //10 ^ 9 Trillion ("trillion"), //10 ^ 12 Quadrillion ("quadrillion"), //10 ^ 15 Quintillion ("quintillion"), //10 ^ 18 (enough for Long.MAX_VALUE) Sextillion ("sextillion"), //10 ^ 21 Septillion ("septillion"), //10 ^ 24 Octillion ("octillion"), //10 ^ 27 Nonillion ("nonillion"), //10 ^ 30 Decillion ("decillion"), //10 ^ 33 Undecillion ("undecillion"), //10 ^ 36 Duodecillion ("duodecillion"), //10 ^ 39 Tredecillion ("tredecillion"), //10 ^ 42 Quattuordecillion ("quattuordecillion"), //10 ^ 45 Quindecillion ("quindecillion"), //10 ^ 48 Sexdecillion ("sexdecillion"), //10 ^ 51 Septendecillion ("septendecillion"), //10 ^ 54 Octodecillion ("octodecillion"), //10 ^ 57 Novemdecillion ("novemdecillion"), //10 ^ 60 Vigintillion ("vigintillion"), //10 ^ 63 ;

    final String display;

    Power(String display) { this.display = display; }

    }

    static enum Digit {

    Zero("zero", "zeroth", "ten", ""),

    One("one", "first", "eleven", "ten"),

    Two("two", "second", "twelve", "twenty"),

    Three("three", "third", "thirteen", "thirty"),

    Four("four", "fourth", "fourteen", "fourty"),

    Five("five", "fifth", "fifteen", "fifty"),

    Six("six", "sixth", "sixteen", "sixty"),

    Seven("seven", "seventh", "seventeen", "seventy"),

    Eight("eight", "eighth", "eighteen", "eighty"),

    Nine("nine", "nineth", "nineteen", "ninety"),

    ;

    final String display, displayOrdinal, plusTen, multiTen;

    Digit(String display, String displayOrdinal,

    String plusTen, String multiTen) {

    this.display = display;

    this.displayOrdinal = displayOrdinal;

    this.plusTen = plusTen;

    this.multiTen = multiTen;

    }

    }

    private static final Map _Ordinals;

    static {

    _Ordinals = new HashMap();

    for(Digit d : Digit.values())

    _Ordinals.put(d.display, d.displayOrdinal);

    }

    @Override

    public String getText(long number) {

    StringBuilder builder = new StringBuilder();

    buildText(builder, number);

    return builder.toString();

    }

    @Override

    public String getOrdinalText(long number) {

    StringBuilder builder = new StringBuilder();

    buildText(builder, number);

    replaceLastTokenWithOrdinal(builder);

    return builder.toString();

    }

    private void buildText(StringBuilder builder, long number) {

    assert builder != null;

    if( number < 0 ) {

    builder.append(getConnectDisplay(Connect.Minus))

    .append(getConnectDisplay(Connect.AfterMinus));

    number = -number;

    }

    String numString = Long.toString(number);

    int power = 0;

    while(numString.length() > (power + 1) * 3)

    power++;

    while(power > 0) {

    boolean modified = extendToken(builder, numString, power * 3);

    if( modified )

    builder.append(getConnectDisplay(Connect.AfterNumber))

    .append(getPowerDisplay(Power.values()[power-1]));

    power--;

    }

    extendToken(builder, Long.toString(number), 0);

    }

    private boolean extendToken(StringBuilder builder,

    String number,

    int suffix) {

    assert builder != null && checkNumber(number) && suffix < number.length();

    int len = number.length() - suffix;

    int hundreds = len > 2 ? (int)(number.charAt(len-3)-'0') : -1;

    int tens = len > 1 ? (int)(number.charAt(len-2)-'0') : -1;

    int inds = (int)(number.charAt(len-1)-'0');

    if( hundreds <= 0 && tens <= 0 && inds <= 0 && suffix > 0 )

    return false;

    else if( len > 3 )

    builder.append(getConnectDisplay(Connect.AfterPower));

    if( hundreds == 0 ) {

    if( len > 3 && (tens > 0 || inds > 0) )

    builder.append(getConnectDisplay(Connect.And))

    .append(getConnectDisplay(Connect.AfterAnd));

    }

    else if( hundreds > 0 ) {

    builder.append(getDigitName(Digit.values()[hundreds]))

    .append(getConnectDisplay(Connect.AfterNumber))

    .append(getConnectDisplay(Connect.Hundred));

    if( tens > 0 || inds > 0 )

    builder.append(getConnectDisplay(Connect.AfterHundred))

    .append(getConnectDisplay(Connect.And))

    .append(getConnectDisplay(Connect.AfterAnd));

    }

    if( tens > 1 ) {

    builder.append(getDigitMultiTen(Digit.values()[tens]));

    if( inds > 0 )

    builder.append(getConnectDisplay(Connect.AfterTen));

    }

    if( tens == 1 )

    builder.append(getDigitPlusTen(Digit.values()[inds]));

    else if( inds > 0 || number.length() == 1 )

    builder.append(getDigitName(Digit.values()[inds]));

    return true;

    }

    private void replaceLastTokenWithOrdinal(StringBuilder builder) {

    assert builder != null && builder.length() > 0;

    int suffix = builder.length()-1;

    while( suffix >= 0 && !isConnect(builder.charAt(suffix)) )

    suffix--;

    String lastToken = builder.substring(suffix+1);

    builder.delete(suffix+1, builder.length()).append(toOrdinal(lastToken));

    }

    String getPowerDisplay(Power power) {

    assert power != null;

    return power.display;

    }

    String getConnectDisplay(Connect connect) {

    assert connect != null;

    return connect.display;

    }

    String getDigitName(Digit digit) {

    assert digit != null;

    return digit.display;

    }

    String toOrdinal(String name) {

    assert name != null && !name.isEmpty();

    String result = _Ordinals.get(name);

    if( result == null ) {

    if( name.charAt(name.length()-1) == 'y' )

    result = name.substring(0, name.length()-1) + "ieth";

    else

    result = name + "th";

    }

    return result;

    }

    String getDigitPlusTen(Digit digit) {

    assert digit != null;

    return digit.plusTen;

    }

    String getDigitMultiTen(Digit digit) {

    assert digit != null;

    return digit.multiTen;

    }

    boolean isConnect(char c) {

    return Connect.isConnect(c);

    }

    }

    /*----------------------------------------------------------------------------

    * English with only Clean Space Connectors

    ---------------------------------------------------------------------------*/

    private static class NumberTextEnglishCleanSpaceOnly

    extends NumberTextEnglish {

    @Override

    String getConnectDisplay(Connect connect) {

    return connect == Connect.AfterTen ?

    " " :

    super.getConnectDisplay(connect);

    }

    }

    /*----------------------------------------------------------------------------

    * Chinese Implementation

    ---------------------------------------------------------------------------*/

    private static class NumberTextChinese extends NumberText {

    static enum Type { Simplified, Traditional; }

    static enum Connect {

    Di ("第", "第"),

    Fu ("负", "負"),

    Ling ("零", "零"),

    Shi ("十", "拾"),

    Bai ("百", "佰"),

    Qian ("千", "仟"),

    ;

    final String display, displayTraditional;

    Connect(String display, String displayTraditional) {

    this.display = display;

    this.displayTraditional = displayTraditional;

    }

    }

    static enum Power {

    Wan ("万", "萬"), //10^4 Yi ("亿", "億"), //10^8 Zhao ("兆", "兆"), //10^12 Jing ("京", "京"), //10^16 (enough for Long.MAX_VALUE) Gai ("垓", "垓"), //10^20 Zi ("秭", "秭"), //10^24 Rang ("穰", "穰"), //10^28 Gou ("沟", "溝"), //10^32 Jian ("涧", "澗"), //10^36 Zheng ("正", "正"), //10^40 Zai ("载", "載"), //10^44 ;

    final String display, displayTraditional;

    Power(String display, String displayTraditional) {

    this.display = display;

    this.displayTraditional = displayTraditional;

    }

    }

    static enum Digit {

    Ling ("零", "零"), //just to occupy this position Yi ("一", "壹"),

    Er ("二", "贰"),

    San ("三", "叁"),

    Si ("四", "肆"),

    Wu ("五", "伍"),

    Liu ("六", "陆"),

    Qi ("七", "柒"),

    Ba ("八", "捌"),

    Jiu ("九", "玖"),

    ;

    final String display, displayTraditional;

    Digit(String display, String displayTraditional) {

    this.display = display;

    this.displayTraditional = displayTraditional;

    }

    }

    private final Type type;

    private NumberTextChinese(Type type) {

    assert type != null;

    this.type = type;

    }

    @Override

    public String getText(long number) {

    StringBuilder builder = new StringBuilder();

    buildText(builder, number);

    return builder.toString();

    }

    @Override

    public String getOrdinalText(long number) {

    StringBuilder builder = new StringBuilder().append("Di");

    buildText(builder, number);

    return builder.toString();

    }

    private void buildText(StringBuilder builder, long number) {

    assert builder != null;

    if( number < 0 ) {

    builder.append(getConnectDisplay(Connect.Fu));

    number = -number;

    }

    String numString = Long.toString(number);

    int power = 0;

    while(numString.length() > (power + 1) * 4)

    power++;

    while(power > 0) {

    if( extendToken(builder, numString, power * 4) )

    builder.append(getPowerDisplay(Power.values()[power-1]));

    power--;

    }

    extendToken(builder, numString, 0);

    }

    private boolean extendToken(StringBuilder builder,

    String number,

    int suffix) {

    assert builder != null && checkNumber(number) && number.length() > suffix;

    int len = number.length() - suffix;

    int qian = len > 3 ? (int)(number.charAt(len-4)-'0') : -1;

    int bai = len > 2 ? (int)(number.charAt(len-3)-'0') : -1;

    int shi = len > 1 ? (int)(number.charAt(len-2)-'0') : -1;

    int ind = (int)(number.charAt(len-1)-'0');

    boolean nonZero = false; //true if any of the digits is not zero if( qian == 0 ) {

    if( bai > 0 || shi > 0 || ind > 0 )

    builder.append(getConnectDisplay(Connect.Ling));

    }

    else if( qian > 0 ){

    builder.append(getDigitDisplay(Digit.values()[qian]))

    .append(getConnectDisplay(Connect.Qian));

    nonZero = true;

    }

    if( bai == 0 ) {

    if( qian > 0 && (shi > 0 || ind > 0) )

    builder.append(getConnectDisplay(Connect.Ling));

    }

    else if( bai > 0 ){

    builder.append(getDigitDisplay(Digit.values()[bai]))

    .append(getConnectDisplay(Connect.Bai));

    nonZero = true;

    }

    if( shi == 0 ) {

    if( bai > 0 && ind > 0 )

    builder.append(getConnectDisplay(Connect.Ling));

    }

    else if( shi > 0 ){

    if( number.length() > 2 || shi != 1 )

    builder.append(getDigitDisplay(Digit.values()[shi]));

    builder.append(getConnectDisplay(Connect.Shi));

    nonZero = true;

    }

    if( ind == 0 ){

    boolean addZero = len == 1;

    for(int i=1; addZero && i<=suffix; i++) {

    if( number.charAt(i) != '0' )

    addZero = false;

    }

    if( addZero ) builder.append(getConnectDisplay(Connect.Ling));

    }

    else {

    builder.append(getDigitDisplay(Digit.values()[ind]));

    nonZero = true;

    }

    return nonZero;

    }

    String getConnectDisplay(Connect connect) {

    assert connect != null;

    return type == Type.Simplified ?

    connect.display :

    connect.displayTraditional;

    }

    String getPowerDisplay(Power power) {

    assert power != null;

    return type == Type.Simplified ?

    power.display :

    power.displayTraditional;

    }

    String getDigitDisplay(Digit digit) {

    assert digit != null;

    return type == Type.Simplified ?

    digit.display :

    digit.displayTraditional;

    }

    }

    }

    展开全文
  • 问题:java字段是int类型等,然后导出时是文本,需要操作人员转换为数字格式. 应操作人员要求,导出的时候就是数字格式可以不用转换,方便操作等 java 后台处理过程:这里我只处理表格的0,2,7,8列的格式转换图: java 代码:...

    问题:java字段是int类型等,然后导出时是文本,需要操作人员转换为数字格式. 应操作人员要求,导出的时候就是数字格式可以不用转换,方便操作等

    fdf66205c297140142f86e4bde480d84.png

    java 后台处理过程:

    这里我只处理表格的0,2,7,8列的格式转换

    图:13d4c4bf82cf9c65760862bd29515e54.png

    java 代码:

    // 总行数

    private int totalRows = 0;

    // 总条数

    private int totalCells = 0;

    // 获取总行数

    public int getTotalRows() {

    return totalRows;

    }

    // 获取总列数

    public int getTotalCells() {

    return totalCells;

    }

    /导出字符串转换成数字格式///

    ///将导出前,已经生成的工作表获取到 workBook,获取第一个工作表0

    Sheet sheet = workbook.getSheetAt(0);

    // 得到Excel的行数

    this.totalRows = sheet.getPhysicalNumberOfRows();

    // 得到Excel的列数(前提是有行数)

    if (totalRows > 1 && sheet.getRow(0) != null) {

    this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();

    }

    // 循环Excel行数 r=3///从第几行 开始需要转换的数据,这里是从第3行开始是导出的真实数据

    for (int r = 3; r < totalRows; r++) {

    Row row = sheet.getRow(r);

    if (row == null) {

    continue;

    }

    for (int c = 0; c < this.totalCells; c++) {/遍历列,对列进行转换就可以了

    Cell cell = row.getCell(c);

    CellStyle cellStyle = workbook.createCellStyle();

    if (null != cell) {

    if (c==0){

    if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {

    String id = String.valueOf(cell.getStringCellValue());

    row.getCell(0).setCellValue(Double.parseDouble(id));

    }

    }

    if (c==2){

    if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {

    String number = String.valueOf(cell.getStringCellValue());

    row.getCell(2).setCellValue(Double.parseDouble(number));

    }

    }

    if (c==7){

    if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {

    String pageViews = String.valueOf(cell.getStringCellValue());

    row.getCell(7).setCellValue(Double.parseDouble(pageViews));

    }

    }

    if (c==8){

    if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {

    String userViews = String.valueOf(cell.getStringCellValue());

    row.getCell(8).setCellValue(Double.parseDouble(userViews));

    }

    }

    }

    }

    }

    导出效果(结果):

    32696fb75464fc480a733d03cd6e59c1.png

    展开全文
  • 问题:java字段是int类型等,然后导出时是文本,需要操作人员转换为数字格式. 应操作人员要求,导出的时候就是数字格式可以不用转换,方便操作等 java 后台处理过程: 这里我只处理表格的0,2,7,8列的格式转换 图: ...
  • Java导出excel时,它默认是文本格式,不能直接二做函数处理,怎么在代码中将他转为数值
  • Java读取Excel表格代码和把数字列转为文本的解决办法。所需 jar 包:dom4j-1.6.1.jar ,poi-3.8-20120326.jar,poi-ooxml-3.8-20120326.jar,poi-ooxml-schemas-3.8-20120326.jar,xmlbeans-2.3.0.jar。下载地址:...
  • Java实现罗马数字转换为阿拉伯数字个人原创,谢谢支持逻辑规则实现代码 个人原创,谢谢支持 代码个人编写,实测有效,,欢迎转载文本链接。 逻辑规则 给定一个罗马数字s,( I<=s<=MMMCMXCIX)(即1到3999)...
  • 中文版还没怎麽测试,如有问题请您告知 raistlic@... import java.util.EnumMap; import java.util.HashMap; import java.util.Map; /** * This class transfers an integer number into a string : * <p...
  • 但是在修改的时候有的时候某个哥的值就莫名其妙的变成了不是文本数字长了就变成了科学计数法的数字,所以在导入的时候做了个这样的判断 导入时候带对科学计数法的处理 //科学计数法转文本 boolean b =...
  • 最近做解析描述时提取到金额字段后,需要将文本中的大写金额转换成数字,然而发现... * 大写金额转数字 * */ public static String ChineseConvertToNumber(String chineseAmount) { if (chineseAmount == null |.
  • 文本)、解析(文本 -> 日期)和规范化。SimpleDateFormat使得可以选择任何用户定日期和时间模式SimpleDateFormawww.cppcns.comt使用方法根据上面的的“日期和时间模式”,设定需要匹配的模式,可以实现String与...
  • 用response.setContentType("application/vnd.ms-...有时候excel会把文本格式直接转换成日期格式。如:8-1成8月1号. 为防止这种情况发生,只需在页面输出的数据前加个  如: (i).get(j)%>
  • 如果你阅读文本并按照一些链接,你会发现char被转换为int.它从未明确表示,如果两个操作数都是char但它是says,则会发生这种情况Widening primitive conversion (§5.1.2) is applied to convert either or both ...
  • 读取文本文件中的字符或数字:  在Java console中显示对应的ASCII码(默认为十进制形式),若想转化为十六进制的形式使用 Integer.toHexString(int i)  例如文本中有a b c 1 2 在读取后显示对应十进制形式(注意...
  • Java intString1 Java intString的介绍我们可以使用String.valueOf() 和Integer.toString() ...2Java intString的应用场景如果我们必须在文本字段中显示数字,通常会使用它,因为所有内容都以字符串形式显示。...
  • 简单编码 Time Limit: 1000MS Memory Limit: 65536KB ...将原来的小写字母全部翻译成大写字母,大写字母全部翻译成小写字母,数字的翻译规律如下: 0——>9 1——>8 2——>7 3——>6 4——>5 5
  • [Java] 纯文本查看 复制代码import java.text.DecimalFormat;import java.util.Scanner;/*** 金额转换*/public class Example {// 大写数字private final static String[] STR_NUMBER = { "零", "壹", "贰", "叁", ...
  • 默认情况下,当文本包含数字值时,这些值使用拉丁(欧洲)数字显示。当首选其他 Unicode 数字形状时,请使用java.awt.font.NumericShaper类。使用NumericShaper API,您可以以任何 Unicode 数字形状显示内部表示为 ...
  • 正则表达式是这个工作的最好的工具;它应该取决于问题规范。以下删除前导零,但如果需要,则留下一个(即,它不会将“0”转换为空白字符串)。s.replaceFirst("^0+(?!$)", "")^ anchor将确保匹配的0在输入的开始。...
  • 不明绝厉在Excel中的单元格中输入数字时,如果在数字前加上一个半角单引号(')则该数字在单元格中的存储格式会自己转为“文本格式”。如果有一列(或一行)数字都是用这种方法输入的,现在又需要将其格式全部转为...
  • 因此,如何将字节从8位值转换为16位Java Unicode字符将不仅在操作系统之间发生变化,而且甚至可以在同一台机器上使用不同代码页的不同用户之间变化。此构造函数只适用于解码您自己的文本文件之一。不要尝试将任意字节...
  • 字符编码和字符集字符编码计算机中储存的信息都是用二进制数表示的,而我们在屏幕上看到的数字、英文、标点符号、汉字等字符是二进制数转换之后的结果。按照某种规则,将字符存储到计算机中,称为编码。反之,将存储...
  • java吧里看到这个问题,近来有空就写了写 import java.util.EnumMap;import java.util.Map;/** * This class transfers an integer number into a string : * <p /> * <pre>{@code * // an ...
  • 文字是人类认知过程中产生的高层认知抽象实体,我们需要将其转换为数字向量或矩阵作为机器学习算法模型以及神经网络模型的标准输入输出。2. 词袋模型(Bag-of-words)Bag-of-words模型是信息检索领域常用的文档表示...
  • java–转换文件编码

    2019-10-20 14:19:42
    计算机中存储的信息都是用二进制数表示的,而我们在屏幕上看到的数字丶英文丶标点符号丶汉字等字符是二进制数转换之后的结果. 根据某种规则,将字符存储到计算机中,称为编码.反之,将存储在计算机中的二进制数按某种...
  • 前言计算机科学中有二进制/八进制/十六进制,以及我们最熟悉的十进制,但十六进制是文本编辑器必须要支持的格式,因为在数据层调试时,要看到数据乱码或不可见字符的数字编码是什么,十六进制比二进制/八进制更容易...
  • 给定一组数字,正则表达式可以找到长度为N的数字子集不止一次,最好是在循环变量N上....鉴于编码文本足够长,可能存在N个空格与长度为N的密钥相关的时间,其以大致明文再现密钥.我测试了这个,例如:" ...
  • 我不确定你的属性可以采用什么值,但也许这个例子可以帮助你:假设我们正在进行一次有监督的学习实验,试图确定一个句号是否...第9,10列:分别在下一个可靠句子分隔符之前的句点的左/右数字(例如,?,!或段落标记)....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 508
精华内容 203
关键字:

java文本转数字

java 订阅