如何使用java从代码中删除行号

时间:2014-05-21 09:49:24

标签: java

我从某个地方复制代码以在eclipse中运行,但该代码有行号。

,例如,

 26   package java.lang;
   27   
   28   import java.util.Properties;
   29   
   30   /**
   31    * The {@code Integer} class wraps a value of the primitive type
   32    * {@code int} in an object. An object of type {@code Integer}
   33    * contains a single field whose type is {@code int}.
   34    *
   35    * <p>In addition, this class provides several methods for converting
   36    * an {@code int} to a {@code String} and a {@code String} to an
   37    * {@code int}, as well as other constants and methods useful when
   38    * dealing with an {@code int}.
   39    *
   40    * <p>Implementation note: The implementations of the "bit twiddling"
   41    * methods (such as {@link #highestOneBit(int) highestOneBit} and
   42    * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
   43    * based on material from Henry S. Warren, Jr.'s <i>Hacker's
   44    * Delight</i>, (Addison Wesley, 2002).
   45    *
   46    * @author  Lee Boynton
   47    * @author  Arthur van Hoff
   48    * @author  Josh Bloch
   49    * @author  Joseph D. Darcy
   50    * @since JDK1.0
   51    */
   52   public final class Integer extends Number implements Comparable<Integer> {
   53       /**
   54        * A constant holding the minimum value an {@code int} can
   55        * have, -2<sup>31</sup>.
   56        */
   57       public static final int   MIN_VALUE = 0x80000000;
   58   
   59       /**
   60        * A constant holding the maximum value an {@code int} can
   61        * have, 2<sup>31</sup>-1.
   62        */
   63       public static final int   MAX_VALUE = 0x7fffffff;
   64   
   65       /**
   66        * The {@code Class} instance representing the primitive type
   67        * {@code int}.
   68        *
   69        * @since   JDK1.1
   70        */
   71       public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
   72   
   73       /**
   74        * All possible chars for representing a number as a String
   75        */
   76       final static char[] digits = {
   77           '0' , '1' , '2' , '3' , '4' , '5' ,
   78           '6' , '7' , '8' , '9' , 'a' , 'b' ,
   79           'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
   80           'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
   81           'o' , 'p' , 'q' , 'r' , 's' , 't' ,
   82           'u' , 'v' , 'w' , 'x' , 'y' , 'z'
   83       };
   84        }

如果文件包含数千行,则无法逐行删除数字。我正在尝试编写算法来从每行中删除行号,但没有成功。我想要这个 -

      package java.lang;

   import java.util.Properties;

   /**
    * The {@code Integer} class wraps a value of the primitive type
    * {@code int} in an object. An object of type {@code Integer}
    * contains a single field whose type is {@code int}.
    *
    * <p>In addition, this class provides several methods for converting
    * an {@code int} to a {@code String} and a {@code String} to an
    * {@code int}, as well as other constants and methods useful when
    * dealing with an {@code int}.
    *
    * <p>Implementation note: The implementations of the "bit twiddling"
    * methods (such as {@link #highestOneBit(int) highestOneBit} and
    * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
    * based on material from Henry S. Warren, Jr.'s <i>Hacker's
    * Delight</i>, (Addison Wesley, 2002).
    *
    * @author  Lee Boynton
    * @author  Arthur van Hoff
    * @author  Josh Bloch
    * @author  Joseph D. Darcy
    * @since JDK1.0
    */
   public final class Integer extends Number implements Comparable<Integer> {
       /**
        * A constant holding the minimum value an {@code int} can
        * have, -2<sup>31</sup>.
        */
       public static final int   MIN_VALUE = 0x80000000;

       /**
        * A constant holding the maximum value an {@code int} can
        * have, 2<sup>31</sup>-1.
        */
       public static final int   MAX_VALUE = 0x7fffffff;

       /**
        * The {@code Class} instance representing the primitive type
        * {@code int}.
        *
        * @since   JDK1.1
        */
       public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");

       /**
        * All possible chars for representing a number as a String
        */
       final static char[] digits = {
           '0' , '1' , '2' , '3' , '4' , '5' ,
           '6' , '7' , '8' , '9' , 'a' , 'b' ,
           'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
           'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
           'o' , 'p' , 'q' , 'r' , 's' , 't' ,
           'u' , 'v' , 'w' , 'x' , 'y' , 'z'
       };

我将感谢你的建议和答案。

2 个答案:

答案 0 :(得分:3)

您可以使用支持正则表达式的文本编辑器(例如notepad ++)并将^(\s+)?\d+替换为任何内容。

说明:

^行开头

(\s+)?空格或无空格

\d+个数字

正如评论中所指出的,你可以使用eclipse,因为它支持基于正则表达式的替换。

记事本++的使用方法:

打开文件,然后用快捷键CTRL + H打开替换对话框,然后将^(\s+)?\d+放入“查找内容:”并确保“替换为:”为空。在左下角设置“正则表达式”的chexkbox。最后点击“全部替换”。

答案 1 :(得分:0)

我还有2个问题的解决方案。有一点不同。如果你这么做很多次,我建议你写一个算法。但如果您使用它一次就可以使用我的方法。

我使用办公程序来做这种事情。

你可以使用excel来做到这一点。 1-将所有行复制到Excel行。 2-使用excel函数剪切前3或4位数字。(你可以使用MID函数:(= MID(包含程序的单元格;起始字符编号;你想要多少个字符))) (如果有一个像1200这样的行号,则4或5作为起始字符) (1000作为你想要的角色) = MID(A1; 5; 1000)

如果行号和代码之间的所有空格相等。你也可以使用word来做到这一点。 1-复制粘贴所有程序行 2-将其转换为表格。使用行号和代码行之间的空格作为列分隔符。 (在&#34;&#34;中的单独文本部分中,您应键入空格五或六次取决于您的程序) 3-删除包含所有行号的第一列。 4-将其转换为文本。