六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 177|回复: 0

(筆記) 如何使用C語言實現split()? (C/C++) (C) (JavaScript)

[复制链接]

升级  82.67%

46

主题

46

主题

46

主题

秀才

Rank: 2

积分
174
 楼主| 发表于 2013-2-5 02:35:56 | 显示全部楼层 |阅读模式
Abstract
寫過JavaScript或ASP的朋友,應該常常用到split()這個函數,他可以輕易地將string轉成array,C語言並沒有相對應的函數,只有strtok()較為接近,稍微加工後,就可以在C語言實現split()。
Introduction
使用環境 : IE 7.0 + Visual Studio 2008

在JavaScript,可以輕易的將string轉成array。
split.htm / JavaScript
<div class="cnblogs_code"><!-- <br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->1 <!-- 
2 (C) OOMusou 2009 http://oomusou.cnblogs.com
3 
4 Filename    : split.htm
5 Compiler    : IE 7.0
6 Description : javaScript's split()
7 Release     : 05/09/2009
8 -->
9 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
10 <html xmlns="http://www.w3.org/1999/xhtml">
11 <head>
12   <script language="javascript" type="text/javascript">
13     function Button1_onclick() {
14       str = "10,20,30";
15       arr = str.split(",");
16      
17       for(i=0; i < 3; i++)
18         document.getElementById("div1").innerHTML += arr + "<br>";
19     }
20   </script>
21 </head>
22 <body>
23   <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
24   <div id="div1">
25   </div>
26 </body>
27 </html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表