首页 \ 问答 \ String.split()java不工作[重复](String.split() java not working [duplicate])

String.split()java不工作[重复](String.split() java not working [duplicate])

这个问题在这里已经有了答案:

我有一个字符串completeString

String completeString = "Comp 30440 Software Engineering Project|20-credit module|Is part of your(Conversion) Programme.Deals with the creation of a twitter sentiment analysis application";

我正在试图分割这个字符串

String[] array = completeString.split("|");  

当我得到第一个元素时

String first = array[0];  

我得到空字符串。 对于接下来的两个元素,我只能得到第一个字母,即C和O(Comp)。


This question already has an answer here:

I have a string completeString

String completeString = "Comp 30440 Software Engineering Project|20-credit module|Is part of your(Conversion) Programme.Deals with the creation of a twitter sentiment analysis application";

I am trying to split this string using

String[] array = completeString.split("|");  

and when I am getting the first element

String first = array[0];  

I am getting empty string. For next two elements I am getting only first letters i.e C and O (Comp).


原文:https://stackoverflow.com/questions/26243457
更新时间:2022-02-27 11:02

最满意答案

我已经找到了我的问题的答案,因为sequelize正在返回结果作为一个对象与数据库结果除了额外的属性,我不得不修改控制器设置和转换结果为原始为了我得到的数组对象来自数据库的查询结果。

index(req,res) {
    User
      .findAll({ raw: true }) // added "raw: true"
      .then(function(users){
        res.json(api.respond(transfomer.transformCollection(users)));
      })
      .catch(function(error){
        res.json(api.respondWithError('users not found',error));
      });
  },

这将返回数据库中的对象数组,并从那里数据转换器正常工作。 感谢您的帮助。


You can use this:

let options = {raw: true, attributes: ['id', 'name', 'code', 'createdAt','updatedAt']};

    country.findAndCountAll(options).then(querySnapshot => {
        let total = querySnapshot.count;
        resolve({docs: querySnapshot.rows, total: total})  
    }).catch((err) => {
        reject(err)
    });

相关问答

更多
  • 根据@iainn的说法,Apache使用的是PHP 7, but the CLI (which Composer uses) is still using 5.6因此尝试再次卸载并安装composer并在安装时选择正确的php版本(7.0)。 检查下面的截图 According to @iainn Apache is using PHP 7, but the CLI (which Composer uses) is still using 5.6 hence, trying to uninstall and ...
  • 首先,Bogdan Bocioaca在他的回答中说,当你只想返回Json时,你只使用Response::json函数(主要用于API,以便其他应用程序可以访问你的json数据)。 例如,下面的代码将返回可能由移动应用程序读取的JSON $worklogs = WorkLog::all(); return Response::json([ 'worklogs' => $worklogs ], $headers); 根据我对您的问题的理解,您希望将数据直接传递给视图,因此理想情况下您的代码应如下所示: ...
  • laracasts.com Laravel的官方网站上有很多教程,还有一个很棒的社区可以帮助你。 laracasts.com Laravel's official website has plenty of tutorials, and a great community able to help you.
  • 给出该错误的行是这样的: $connection = new PDO($dsn, $username, $password, $this->options($config)); 它正在尝试为pg加载PDO驱动程序。 你是否检查过在PHP配置文件中启用了pdo扩展? 检查/etc/php.d/pgsql.ini和/etc/php.d/pdo.ini 。 希望这可以帮助。 The line giving that error is this: $connection = new PDO($dsn, $user ...
  • 我能够通过以下步骤解决我的问题 1.在你的.env中,添加另一个数据库连接参数,例如 DB_CONNECTION=mysql DB_HOST=localhost DB_DATABASE=database1 DB_USERNAME=username1 DB_PASSWORD=password1 DB_HOST=host1 DB_EXT_CONNECTION=mysql DB_EXT_DATABASE=database2 DB_EXT_USERNAME=username2 DB_EXT_PASSWORD=pa ...
  • 架构基本上就是您希望前端的JSON读取它的方式。 你在显示通知吗? 然后研究如何构建。 Firebase将使您能够将更新推送到前端,然后将不再需要通过API提取数据,以显示通知所需的实际数据。 The schema will basically be how you want your JSON for your front-end will read it. Are you displaying notifications? Then investigate how that would be struc ...
  • 我已经找到了我的问题的答案,因为sequelize正在返回结果作为一个对象与数据库结果除了额外的属性,我不得不修改控制器设置和转换结果为原始为了我得到的数组对象来自数据库的查询结果。 index(req,res) { User .findAll({ raw: true }) // added "raw: true" .then(function(users){ res.json(api.respond(transfomer.transformCollectio ...
  • javascript警告是由你的return false;引起的return false; 。 如果你需要它(除非你想捕获回车键,似乎没有必要用于keyup事件),你应该做的事情如下: $(".search").keyup(function(e) { e.preventDefault(); // prevent the default action of the event 我对Laravel不熟悉,但在我看来,你没有得到任何结果,因为你没有对控制器中的$data变量做任何事情。 我猜你需要 ...
  • Laravel 4.1中的中间件功能受到一些php项目的启发,并被采纳用于为框架提供核心中间件功能。 项目的中间件实现依赖于HttpKernelInterface,并且引入了这样的约定:通过装饰HttpKernelInterface实例,我们可以添加尽可能多的层到应用程序的请求/响应处理堆栈,而无需修改实际的应用程序对象。 在Laravel 5中,使用中间件是钩住框架的Http层的首选方式.Laravel 5有自己的中间件实现。 应该使用它们来代替过滤器。 Kernel类现在注册应用程序级中间件,引导核心组 ...
  • 首先,请注意这是Laravel 5.3中基于数据库的队列中作业的格式。 较新版本的Laravel包含更改。 有效负载列应包含以下格式的json对象。 在这种情况下,作业( ...\\CallQueuedHandler@call )可以进行硬编码。 我相信commandName键仅用于显示目的。 但是,命令键是更难的部分,它应该是unserialize()支持的有效对象。 看起来npm上有可用于此目的的软件包,快速搜索出现了php序列化 。 { "job": "Illuminate\\Queue\\C ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)