charAt()找不到符号

时间:2018-02-27 16:27:19

标签: java string-length charat cannot-find-symbol

我正在尝试使用看起来像这样的if语句。如果某个方法在其line类型的参数String中收到了参数,那么在使用cannot find symbol调用时,为什么会出现line.charAt(x)错误?这是代码片段。

for(int x = 0; x < line.length; x++) {
    if(line.charAt(x) != ' ') {
        //rest of code
    }
}

此外,length来电也有cannot find symbol错误。

任何人都可以在不导入课程内容的情况下看到解决方案吗?感谢。

3 个答案:

答案 0 :(得分:0)

在Java中,要查找String的长度,我们需要使用String.length()

for(int x = 0; x < line.length(); x++) {
    if(line.charAt(x) != ' ') {
        //code
    }
}

答案 1 :(得分:0)

您在Java中使用$this->load_acf_fields();时正在使用<?php class MyClassCustomFields extends MyClass { public function __construct() { parent::__construct(); $this->load_acf_fields(); } /** * Load ACF Fields */ public function load_acf_fields() { if( function_exists('acf_add_local_field_group') ): acf_add_local_field_group(array ( 'key' => 'group_c5mzpj3e3kazq', 'title' => 'Home Page Meta', 'fields' => array ( array ( 'key' => 'field_q5tdea0fgotbd', 'label' => 'Custom Heading', 'name' => 'home_custom_heading', 'type' => 'text', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', ), ), 'location' => array ( array ( array ( 'param' => 'page_type', 'operator' => '==', 'value' => 'front_page', ), ), ), 'menu_order' => 0, 'position' => 'normal', 'style' => 'seamless', 'label_placement' => 'top', 'instruction_placement' => 'label', 'active' => 1, 'description' => '', )); endif; } } 。详细了解line.length以及here以外的其他字符串工具。

答案 2 :(得分:0)

试试这个

   String line = "JAva java java";
    for(int x = 0; x < line.length(); x++) {
        if(line.charAt(x) != ' ') {
            System.out.println("text-->"+line.charAt(x));
        }
    }
相关问题