编写代码以处理单词列表并修剪单词中的所有空格 [英] Write the code to process the list of words and trim any spaces out of the words

查看:44
本文介绍了编写代码以处理单词列表并修剪单词中的所有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该代码应检查字符串数组,并查看单词之间是否有空格.这是一个示例:{每个",附近",检查",食物",立场",价值"}.应该更改为:{每一个",捏合",检查",食物",立场",价值"}.到目前为止,这是我的代码:

This code is supposed to check through an array of strings and see if there is a space between a word. Here is an example: {"every", "near ing", " checking", "food ", "stand", "value "}. It should be changed to hold: {"every", "nearing", "checking", "food", "stand", "value"}. Here is my code so far:

package space;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class spacefinder {
   public static void main (String[] args) {
      String[] arr = {"every", "near ing", "checking", "food", "stand", "value"};
      Pattern pattern = Pattern.compile("\\arr");
      Matcher matcher = pattern.matcher(arr);
      boolean found = matcher.find();
   }
}   

此代码会导致错误,并且我看到的每个教程都没有使用字符串数组,例如我的情况是String [] Arr,它们仅使用常规的String =语句.

This code results in an error, and every tutorial I see does not use a string array, such as the String[] Arr in my case, they only use a regular String = statement.

推荐答案

您可以尝试执行以下操作:

You can try something like this:

for(int i = 0; i<arr.length; i++) {
    arr[i] = arr[i].replace(" ", "");
}

这篇关于编写代码以处理单词列表并修剪单词中的所有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆