分割一个JavaScript字符串 [英] split a javascript string

查看:79
本文介绍了分割一个JavaScript字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我有一个JavaScript字符串,它是Ajax异步操作的结果.

代码:

var xmlHttp_obj = new XmlHttpRequest( );

 xmlHttp_obj.onreadystatechange = function( ) {
                                 if ( xmlHttp_obj.readyState == 4) // ready 
                                {
                                  var cities_List = xmlHttp_obj.responseText;
                                  // what to do NEXT??
                                 
                                }
                              }

 xmlHttp_obj.open("POST", "http://localhost/" + window.location.host + "/TestASP_NET/AsyncTest.ashx", true);

xmlHttp_obj.send(null);



传入的字符串包含由换行符(\ n)
分隔的城市
如何从列表中获取每个城市?
什么正则表达式?

解决方案

根据城市之间的分隔符来解析字符串?认真地说,这只是一个简单的字符串操作.不幸的是,您没有提供有关字符串返回的格式的任何信息,因此几乎没有任何人可以告诉您您必须执行的操作.


Hi!

I have a javascript string which is the result of Ajax async operation.

code:

var xmlHttp_obj = new XmlHttpRequest( );

 xmlHttp_obj.onreadystatechange = function( ) {
                                 if ( xmlHttp_obj.readyState == 4) // ready 
                                {
                                  var cities_List = xmlHttp_obj.responseText;
                                  // what to do NEXT??
                                 
                                }
                              }

 xmlHttp_obj.open("POST", "http://localhost/" + window.location.host + "/TestASP_NET/AsyncTest.ashx", true);

xmlHttp_obj.send(null);



The incoming string contains cities sperated by a linebreak (\n)

How do I get each city from a list?
What regex?

解决方案

Parse the string based on whatever separator is between the cities?? Seriously, this is just a simple string manipulation. Unfortunately for you, you didn''t supply any information on what format the string comes back in, so there''s little to nothing anyone can tell you about what you have to do.


这篇关于分割一个JavaScript字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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