1. PHP encryption and decryption
PHP encryption and decryption functions can be used to encrypt some useful strings stored in the database, and reversibly decrypt the strings. This function uses base64 and MD5 encryption and decryption.
<span> 1</span> <span>function</span> encryptDecrypt(<span>$key</span>, <span>$string</span>, <span>$decrypt</span><span>){ </span><span> 2</span> <span> 3</span> <span>if</span>(<span>$decrypt</span><span>){ </span><span> 4</span> <span> 5</span> <span>$decrypted</span> = <span>rtrim</span>(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, <span>md5</span>(<span>$key</span>), <span>base64_decode</span> <span> 6</span> (<span>$string</span>), MCRYPT_MODE_CBC, <span>md5</span>(<span>md5</span>(<span>$key</span>))), "12"<span>); </span><span> 7</span> <span> 8</span> <span>return</span> <span>$decrypted</span><span>; </span><span> 9</span> <span>10</span> }<span>else</span><span>{ </span><span>11</span> <span>12</span> <span>$encrypted</span> = <span>base64_encode</span>(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, <span>md5</span>(<span>$key</span>), <span>13</span> <span>$string</span>, MCRYPT_MODE_CBC, <span>md5</span>(<span>md5</span>(<span>$key</span><span>)))); </span><span>14</span> <span>15</span> <span>return</span> <span>$encrypted</span><span>; </span><span>16</span> <span>17</span> <span> } </span><span>18</span> <span>19</span> }
How to use is as follows:
<span>1</span> <span>//</span><span>以下是将字符串“Helloweba欢迎您”分别加密和解密 </span><span>2</span> <span>3</span> <span>//加密: </span> <span>4</span> <span>5</span> <span>echo</span> encryptDecrypt('password', 'Helloweba欢迎您',0<span>); </span><span>6</span> <span>7</span> <span>//</span><span>解密: </span> <span>8</span> <span>9</span> <span>echo</span> encryptDecrypt('password', 'z0JAx4qMwcF+db5TNbp/xwdUM84snRsXvvpXuaCa4Bk=',1);
2. PHP generates random strings
When we need to generate a random name, temporary password and other strings, we can use the following function:
<span> 1</span> <span>function</span> generateRandomString(<span>$length</span> = 10<span>) { </span><span> 2</span> <span> 3</span> <span>$characters</span> = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'<span>; </span><span> 4</span> <span> 5</span> <span>$randomString</span> = ''<span>; </span><span> 6</span> <span> 7</span> <span>for</span> (<span>$i</span> = 0; <span>$i</span> $length; <span>$i</span>++<span>) { </span><span> 8</span> <span> 9</span> <span>$randomString</span> .= <span>$characters</span>[<span>rand</span>(0, <span>strlen</span>(<span>$characters</span>) - 1<span>)]; </span><span>10</span> <span>11</span> <span> } </span><span>12</span> <span>13</span> <span>return</span> <span>$randomString</span><span>; </span><span>14</span> <span>15</span> }
How to use it:
<span>1</span> <span>echo</span> generateRandomString(20);
3. PHP gets the file extension (suffix)
The following function can quickly obtain the file extension or suffix.
<span>1</span> <span>function</span> getExtension(<span>$filename</span><span>){ </span><span>2</span> <span>3</span> <span>$myext</span> = <span>substr</span>(<span>$filename</span>, <span>strrpos</span>(<span>$filename</span>, '.'<span>)); </span><span>4</span> <span>5</span> <span>return</span> <span>str_replace</span>('.','',<span>$myext</span><span>); </span><span>6</span> <span>7</span> }
How to use is as follows:
<span>1</span> <span>$filename</span> = '我的文档.doc'<span>; </span><span>2</span> <span>3</span> <span>echo</span> getExtension(<span>$filename</span>);
4. PHP gets the file size and formats it
The functions used below can get the size of the file and convert it into easy-to-read KB, MB and other formats.
<span> 1</span> <span>function</span> formatSize(<span>$size</span><span>) { </span><span> 2</span> <span> 3</span> <span>$sizes</span> = <span>array</span>(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"<span>); </span><span> 4</span> <span> 5</span> <span>if</span> (<span>$size</span> == 0<span>) { </span><span> 6</span> <span> 7</span> <span>return</span>('n/a'<span>); </span><span> 8</span> <span> 9</span> } <span>else</span><span> { </span><span>10</span> <span>11</span> <span>return</span> (<span>round</span>(<span>$size</span>/<span>pow</span>(1024, (<span>$i</span> = <span>floor</span>(<span>log</span>(<span>$size</span>, 1024)))), 2) . <span>$sizes</span>[<span>$i</span><span>]); </span><span>12</span> <span>13</span> <span> } </span><span>14</span> <span>15</span> }
How to use is as follows:
<span>1</span> <span>$thefile</span> = <span>filesize</span>('test_file.mp3'<span>); </span><span>2</span> <span>3</span> <span>echo</span> formatSize(<span>$thefile</span>);
5. Replace tag characters with PHP
Sometimes we need to replace strings and template tags with specified content, we can use the following function:
<span> 1</span> <span>function</span> stringParser(<span>$string</span>,<span>$replacer</span><span>){ </span><span> 2</span> <span> 3</span> <span>$result</span> = <span>str_replace</span>(<span>array_keys</span>(<span>$replacer</span>), <span>array_values</span>(<span>$replacer</span>),<span>$string</span><span>); </span><span> 4</span> <span> 5</span> <span>return</span> <span>$result</span><span>; </span><span> 6</span> <span> 7</span> <span>} </span><span> 8</span> <span> 9</span> <span>//</span><span>使用方法如下</span> <span>10</span> <span>11</span> <span>$string</span> = '<span>The {b}anchor text{/b} is the {b}actual word{/b} or words used </span><span>12</span> {br}to describe the link {br}itself'<span>; </span><span>13</span> <span>14</span> <span>$replace_array</span> = <span>array</span>('{b}' => '<b>','{/b}' => '</b>','{br}' => '<br>'<span>); </span><span>15</span> <span>16</span> <span>17</span> <span>18</span> <span>echo</span> stringParser(<span>$string</span>,<span>$replace_array</span>);
6. PHP lists the file names in the directory
If you want to list all files in a directory, use the following code:
<span> 1</span> <span>function</span> listDirFiles(<span>$DirPath</span><span>){ </span><span> 2</span> <span> 3</span> <span>if</span>(<span>$dir</span> = <span>opendir</span>(<span>$DirPath</span><span>)){ </span><span> 4</span> <span> 5</span> <span>while</span>((<span>$file</span> = <span>readdir</span>(<span>$dir</span>))!== <span>false</span><span>){ </span><span> 6</span> <span> 7</span> <span>if</span>(!<span>is_dir</span>(<span>$DirPath</span>.<span>$file</span><span>)) </span><span> 8</span> <span> 9</span> <span> { </span><span>10</span> <span>11</span> <span>echo</span> "filename: <span>$file</span><br>"<span>; </span><span>12</span> <span>13</span> <span> } </span><span>14</span> <span>15</span> <span> } </span><span>16</span> <span>17</span> <span> } </span><span>18</span> <span>19</span> <span>} </span><span>20</span> <span>21</span> <span>//</span><span>使用方法如下</span> <span>22</span> <span>23</span> listDirFiles('home/some_folder/');
7. Get the current page URL with PHP
The following function can get the URL of the current page, whether it is http or https.
<span> 1</span> <span>function</span><span> curPageURL() { </span><span> 2</span> <span> 3</span> <span>$pageURL</span> = 'http'<span>; </span><span> 4</span> <span> 5</span> <span>if</span> (!<span>empty</span>(<span>$_SERVER</span>['HTTPS'])) {<span>$pageURL</span> .= "s"<span>;} </span><span> 6</span> <span> 7</span> <span>$pageURL</span> .= "://"<span>; </span><span> 8</span> <span> 9</span> <span>if</span> (<span>$_SERVER</span>["SERVER_PORT"] != "80"<span>) { </span><span>10</span> <span>11</span> <span>$pageURL</span> .= <span>$_SERVER</span>["SERVER_NAME"].":".<span>$_SERVER</span>["SERVER_PORT"].<span>$_SERVER</span> <span>12</span> ["REQUEST_URI"<span>]; </span><span>13</span> <span>14</span> } <span>else</span><span> { </span><span>15</span> <span>16</span> <span>$pageURL</span> .= <span>$_SERVER</span>["SERVER_NAME"].<span>$_SERVER</span>["REQUEST_URI"<span>]; </span><span>17</span> <span>18</span> <span> } </span><span>19</span> <span>20</span> <span>return</span> <span>$pageURL</span><span>; </span><span>21</span> <span>22</span> <span>} </span><span>23</span> <span>24</span> <span>//</span><span>使用方法如下</span> <span>25</span> <span>26</span> <span>echo</span> curPageURL();
8. PHP forced download of files
Sometimes we don’t want the browser to directly open a file, such as a PDF file, but to download the file directly, then the following function can force the file to be downloaded. The application/octet-stream header type is used in the function.
<span> 1</span> <span>function</span> download(<span>$filename</span><span>){ </span><span> 2</span> <span> 3</span> <span>if</span> ((<span>isset</span>(<span>$filename</span>))&&(<span>file_exists</span>(<span>$filename</span><span>))){ </span><span> 4</span> <span> 5</span> <span>header</span>("Content-length: ".<span>filesize</span>(<span>$filename</span><span>)); </span><span> 6</span> <span> 7</span> <span>header</span>('Content-Type: application/octet-stream'<span>); </span><span> 8</span> <span> 9</span> <span>header</span>('Content-Disposition: attachment; filename="' . <span>$filename</span> . '"'<span>); </span><span>10</span> <span>11</span> <span>readfile</span>("<span>$filename</span>"<span>); </span><span>12</span> <span>13</span> } <span>else</span><span> { </span><span>14</span> <span>15</span> <span>echo</span> "Looks like file does not exist!"<span>; </span><span>16</span> <span>17</span> <span> } </span><span>18</span> <span>19</span> <span>} </span><span>20</span> <span>21</span> <span>//</span><span>使用方法如下</span> <span>22</span> <span>23</span> download('/down/test_45f73e852.zip');
9. PHP intercepts string length
We often encounter situations where we need to intercept the length of a string (including Chinese characters). For example, the title display cannot exceed how many characters. The excess length is represented by.... The following function can meet your needs.
<span> 1</span> <span>/*</span> <span> 2</span> <span> 3</span> <span> Utf-8、gb2312都支持的汉字截取函数 </span><span> 4</span> <span> 5</span> <span> cut_str(字符串, 截取长度, 开始长度, 编码); </span><span> 6</span> <span> 7</span> <span> 编码默认为 utf-8 </span><span> 8</span> <span> 9</span> <span> 开始长度默认为 0 </span><span>10</span> <span>11</span> <span>*/</span> <span>12</span> <span>13</span> <span>function</span> cutStr(<span>$string</span>, <span>$sublen</span>, <span>$start</span> = 0, <span>$code</span> = 'UTF-8'<span>){ </span><span>14</span> <span>15</span> <span>if</span>(<span>$code</span> == 'UTF-8'<span>){ </span><span>16</span> <span>17</span> <span>$pa</span> = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"<span>; </span><span>18</span> <span>19</span> <span>preg_match_all</span>(<span>$pa</span>, <span>$string</span>, <span>$t_string</span><span>); </span><span>20</span> <span>21</span> <span>22</span> <span>23</span> <span>if</span>(<span>count</span>(<span>$t_string</span>[0]) - <span>$start</span> > <span>$sublen</span>) <span>return</span> <span>join</span>('', <span>array_slice</span> <span>24</span> (<span>$t_string</span>[0], <span>$start</span>, <span>$sublen</span>))."..."<span>; </span><span>25</span> <span>26</span> <span>return</span> <span>join</span>('', <span>array_slice</span>(<span>$t_string</span>[0], <span>$start</span>, <span>$sublen</span><span>)); </span><span>27</span> <span>28</span> }<span>else</span><span>{ </span><span>29</span> <span>30</span> <span>$start</span> = <span>$start</span>*2<span>; </span><span>31</span> <span>32</span> <span>$sublen</span> = <span>$sublen</span>*2<span>; </span><span>33</span> <span>34</span> <span>$strlen</span> = <span>strlen</span>(<span>$string</span><span>); </span><span>35</span> <span>36</span> <span>$tmpstr</span> = ''<span>; </span><span>37</span> <span>38</span> <span>39</span> <span>40</span> <span>for</span>(<span>$i</span>=0; <span>$i</span>$strlen; <span>$i</span>++<span>){ </span><span>41</span> <span>42</span> <span>if</span>(<span>$i</span>>=<span>$start</span> && <span>$i</span>$start+<span>$sublen</span><span>)){ </span><span>43</span> <span>44</span> <span>if</span>(<span>ord</span>(<span>substr</span>(<span>$string</span>, <span>$i</span>, 1))>129<span>){ </span><span>45</span> <span>46</span> <span>$tmpstr</span>.= <span>substr</span>(<span>$string</span>, <span>$i</span>, 2<span>); </span><span>47</span> <span>48</span> }<span>else</span><span>{ </span><span>49</span> <span>50</span> <span>$tmpstr</span>.= <span>substr</span>(<span>$string</span>, <span>$i</span>, 1<span>); </span><span>51</span> <span>52</span> <span> } </span><span>53</span> <span>54</span> <span> } </span><span>55</span> <span>56</span> <span>if</span>(<span>ord</span>(<span>substr</span>(<span>$string</span>, <span>$i</span>, 1))>129) <span>$i</span>++<span>; </span><span>57</span> <span>58</span> <span> } </span><span>59</span> <span>60</span> <span>if</span>(<span>strlen</span>(<span>$tmpstr</span>)$strlen ) <span>$tmpstr</span>.= "..."<span>; </span><span>61</span> <span>62</span> <span>return</span> <span>$tmpstr</span><span>; </span><span>63</span> <span>64</span> <span> } </span><span>65</span> <span>66</span> <span>} </span><span>67</span> <span>68</span> <span>//</span><span>使用方法如下</span> <span>69</span> <span>70</span> <span>$str</span> = "jQuery插件实现的加载图片和页面效果"<span>; </span><span>71</span> <span>72</span> <span>echo</span> cutStr(<span>$str</span>,16);
10. Get the real IP of the client with PHP
We often use a database to record the user’s IP. The following code can obtain the client’s real IP:
<span> 1</span> <span>//</span><span>获取用户真实IP </span> <span> 2</span> <span> 3</span> <span>function</span><span> getIp() { </span><span> 4</span> <span> 5</span> <span>if</span> (<span>getenv</span>("HTTP_CLIENT_IP") && <span>strcasecmp</span>(<span>getenv</span>("HTTP_CLIENT_IP"), <span> 6</span> "unknown"<span>)) </span><span> 7</span> <span> 8</span> <span>$ip</span> = <span>getenv</span>("HTTP_CLIENT_IP"<span>); </span><span> 9</span> <span>10</span> <span>else</span> <span>11</span> <span>12</span> <span>if</span> (<span>getenv</span>("HTTP_X_FORWARDED_FOR") && <span>strcasecmp</span>(<span>getenv</span>("HTTP_X_FORWARDED_FOR"), "unknown"<span>)) </span><span>13</span> <span>14</span> <span>$ip</span> = <span>getenv</span>("HTTP_X_FORWARDED_FOR"<span>); </span><span>15</span> <span>16</span> <span>else</span> <span>17</span> <span>18</span> <span>if</span> (<span>getenv</span>("REMOTE_ADDR") && <span>strcasecmp</span>(<span>getenv</span>("REMOTE_ADDR"), "unknown"<span>)) </span><span>19</span> <span>20</span> <span>$ip</span> = <span>getenv</span>("REMOTE_ADDR"<span>); </span><span>21</span> <span>22</span> <span>else</span> <span>23</span> <span>24</span> <span>if</span> (<span>isset</span> (<span>$_SERVER</span>['REMOTE_ADDR']) && <span>$_SERVER</span>['REMOTE_ADDR'] && <span>25</span> <span>strcasecmp</span>(<span>$_SERVER</span>['REMOTE_ADDR'], "unknown"<span>)) </span><span>26</span> <span>27</span> <span>$ip</span> = <span>$_SERVER</span>['REMOTE_ADDR'<span>]; </span><span>28</span> <span>29</span> <span>else</span> <span>30</span> <span>31</span> <span>$ip</span> = "unknown"<span>; </span><span>32</span> <span>33</span> <span>return</span> (<span>$ip</span><span>); </span><span>34</span> <span>35</span> <span>} </span><span>36</span> <span>37</span> <span>//</span><span>使用方法如下</span> <span>38</span> <span>39</span> <span>echo</span> getIp();
11. PHP prevents SQL injection
When we query the database, for security reasons, we need to filter some illegal characters to prevent malicious SQL injection. Please take a look at the function:
<span> 1</span> <span>function</span> injCheck(<span>$sql_str</span><span>) { </span><span> 2</span> <span> 3</span> <span>$check</span> = <span>preg_match</span>('<span>/select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into </span><span> 4</span> |load_file|outfile/', <span>$sql_str</span><span>); </span><span> 5</span> <span> 6</span> <span>if</span> (<span>$check</span><span>) { </span><span> 7</span> <span> 8</span> <span>echo</span> '非法字符!!'<span>; </span><span> 9</span> <span>10</span> <span>exit</span><span>; </span><span>11</span> <span>12</span> } <span>else</span><span> { </span><span>13</span> <span>14</span> <span>return</span> <span>$sql_str</span><span>; </span><span>15</span> <span>16</span> <span> } </span><span>17</span> <span>18</span> <span>} </span><span>19</span> <span>20</span> <span>//</span><span>使用方法如下</span> <span>21</span> <span>22</span> <span>echo</span> injCheck('1 or 1=1');
12. PHP page prompts and jumps
When we perform form operations, sometimes we need to prompt the user for the operation results and jump to the relevant page for the sake of friendliness. Please see the following function:
<span> 1</span> <span>function</span> message(<span>$msgTitle</span>,<span>$message</span>,<span>$jumpUrl</span><span>){ </span><span> 2</span> <span>$str</span> = ''<span>; </span><span> 3</span> <span>$str</span> .= ''<span>; </span><span> 4</span> <span>$str</span> .= ''<span>; </span><span> 5</span> <span>$str</span> .= '<meta charset="utf-8">'<span>; </span><span> 6</span> <span>$str</span> .= '<title>页面提示</title>'<span>; </span><span> 7</span> <span>$str</span> .= '<style type="text/css">'<span>; <span> 8 <span>$str .= '<span>*{margin:0; padding:0}a{color:#369; text-decoration:none;}a:hover{text-decoration:underline}body{height:100%; font:12px/18px Tahoma, Arial, sans-serif; color:#424242; background:#fff}.message{width:450px; height:120px; <span> 9 <span>margin:16% auto; border:1px solid #99b1c4; background:#ecf7fb}.message h3{height:28px; <span>10 line-height:28px; background:#2c91c6; text-align:center; color:#fff; font-size:14px}.msg_txt{padding:10px; margin-top:8px}.msg_txt h4{line-height:26px; font-size:14px}.msg_txt h4.red{color:#f30}.msg_txt p{line-height:22px}'<span>; <span>11 <span>$str .= '</style>'<span>; </span><span>12</span> <span>$str</span> .= ''<span>; </span><span>13</span> <span>$str</span> .= ''<span>; </span><span>14</span> <span>$str</span> .= '<div>'<span>; </span><span>15</span> <span>$str</span> .= '<h3 id="span-msgTitle-span">'.<span>$msgTitle</span>.'</h3>'<span>; </span><span>16</span> <span>$str</span> .= '<div>'<span>; </span><span>17</span> <span>$str</span> .= '<h4 id="span-message-span">'.<span>$message</span>.'</h4>'<span>; </span><span>18</span> <span>$str</span> .= '<p>系统将在 <span>3</span> 秒后自动跳转,如果不想等待,直接点击 <a href="%7B%24jumpUrl%7D">这里</a> 跳转</p>'<span>; </span><span>19</span> <span>$str</span> .= "<script>setTimeout('location.replace(\'".<span>$jumpUrl."\')',2000)</script>"<span>; </span><span>20</span> <span>$str</span> .= '</div>'<span>; </span><span>21</span> <span>$str</span> .= '</div>'<span>; </span><span>22</span> <span>$str</span> .= ''<span>; </span><span>23</span> <span>$str</span> .= ''<span>; </span><span>24</span> <span>echo</span> <span>$str</span><span>; </span><span>25</span> <span>} </span><span>26</span> <span>27</span> <span>//</span><span>使用方法如下 </span> <span>28</span> <span>29</span> message('操作提示','操作成功!','http://www.helloweba.com/');
13. PHP calculation time
When we process time, we need to calculate the length of time from the current time to a certain point in time. For example, when calculating the running time of the client, it is usually expressed by hh:mm:ss.
<span> 1</span> <span>function</span> changeTimeType(<span>$seconds</span><span>) { </span><span> 2</span> <span> 3</span> <span>if</span> (<span>$seconds</span> > 3600<span>) { </span><span> 4</span> <span> 5</span> <span>$hours</span> = <span>intval</span>(<span>$seconds</span> / 3600<span>); </span><span> 6</span> <span> 7</span> <span>$minutes</span> = <span>$seconds</span> % 3600<span>; </span><span> 8</span> <span> 9</span> <span>$time</span> = <span>$hours</span> . ":" . <span>gmstrftime</span>('%M:%S', <span>$minutes</span><span>); </span><span>10</span> <span>11</span> } <span>else</span><span> { </span><span>12</span> <span>13</span> <span>$time</span> = <span>gmstrftime</span>('%H:%M:%S', <span>$seconds</span><span>); </span><span>14</span> <span>15</span> <span> } </span><span>16</span> <span>17</span> <span>return</span> <span>$time</span><span>; </span><span>18</span> <span>19</span> <span>} </span><span>20</span> <span>21</span> <span>//</span><span>使用方法如下</span> <span>22</span> <span>23</span> <span>$seconds</span> = 3712<span>; </span><span>24</span> <span>25</span> <span>echo</span> changeTimeType(<span>$seconds</span>);
The above has introduced a summary of super practical PHP functions, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

使用Java的String.valueOf()函数将基本数据类型转换为字符串在Java开发中,当我们需要将基本数据类型转换为字符串时,一种常见的方法是使用String类的valueOf()函数。这个函数可以接受基本数据类型的参数,并返回对应的字符串表示。在本文中,我们将探讨如何使用String.valueOf()函数进行基本数据类型转换,并提供一些代码示例来

char数组转string的方法:可以通过赋值来实现,使用{char a[]=" abc d\0efg ";string s=a;}语法,让char数组对string直接赋值,执行代码即可完成转换。

大家好,今天给大家分享java基础知识之String。String类的重要性就不必说了,可以说是我们后端开发用的最多的类,所以,很有必要好好来聊聊它。

使用Java的String.replace()函数替换字符串中的字符(串)在Java中,字符串是不可变的对象,这意味着一旦创建了一个字符串对象,就无法修改它的值。但是,你可能会遇到需要替换字符串中的某些字符或者字符串的情况。这时候,我们可以使用Java的String类中的replace()方法来实现字符串的替换。String类的replace()方法有两种重

一、认识String1.JDK中的String首先我们看看JDK中的String类源码,它实现了很多接口,可以看到String类被final修饰了,这就说明String类不可以被继承,String不存在子类,这样所有使用JDK的人,用到的String类都是同一个,如果String允许被继承,每个人都可以对String进行扩展,每个人使用的String都不是同一个版本,两个不同的人使用相同的方法,表现出不同的结果,这就导致代码没办法进行开发了继承和方法覆写在带来灵活性的同时,也会带来很多子类行为不

使用Java的String.length()函数获取字符串的长度在Java编程中,字符串是一种非常常见的数据类型,我们经常需要获取字符串的长度,即字符串中字符的个数。在Java中,我们可以使用String类的length()函数来获取字符串的长度。下面是一个简单的示例代码:publicclassStringLengthExample{publ

String中split方法使用String的split()方法用于按传入的字符或字符串对String进行拆分,返回拆分之后的数组。1、一般用法用一般的字符,例如@或,等符号做分隔符时:Stringaddress="上海@上海市@闵行区@吴中路";String[]splitAddr=address.split("@");System.out.println(splitAddr[0]+splitAddr[1]+splitAddr[2]+splitAddr[3

在Golang编程中,byte、rune和string类型是非常基础、常见的数据类型。它们在处理字符串、文件流等数据操作时发挥着重要作用。而在进行这些数据操作时,我们通常需要对它们进行相互的转换,这就需要掌握一些转换技巧。本文将介绍Golang函数的byte、rune和string类型转换技巧,旨在帮助读者更好地理解这些数据类型,并能够熟练地在编程实践中应用


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
