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) });
相关问答
更多-
Laravel 5.5。(Laravel 5.5. and PHP 7)[2022-04-03]
根据@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 ...
-
NodeJs:像Laravel PHP Framework中的数据转换器(NodeJs: Data Transformers like in Laravel PHP Framework)[2023-05-08]
我已经找到了我的问题的答案,因为sequelize正在返回结果作为一个对象与数据库结果除了额外的属性,我不得不修改控制器设置和转换结果为原始为了我得到的数组对象来自数据库的查询结果。 index(req,res) { User .findAll({ raw: true }) // added "raw: true" .then(function(users){ res.json(api.respond(transfomer.transformCollectio ... -
在Laravel 4 PHP Framework中搜索数据库中的表(Search for a table within a database in Laravel 4 PHP Framework)[2022-10-07]
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 ...