MySQL在字符串前添加空格

时间:2015-02-08 20:22:34

标签: c# php mysql

所以我使用MySQL和C#来从数据库中获取信息,但是当我尝试在MySQL中再次使用该数据库信息时,它不起作用,因为它似乎在增加一个小空间前面的数据。让我告诉你我的意思。

在网页上显示信息的php代码

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$nick = $_POST["myform_nick"];

$sql = "SELECT Lin FROM scores WHERE name='$nick'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
 // output data of each row
 while($row = mysqli_fetch_assoc($result)) {
     echo $row["Lin"];
 }

}

然后在C#中就是这样......

IEnumerator LeagueCheck(){
     var form = new WWWForm ();
     form.AddField( "myform_nick", formNick );
     WWW w = new WWW (URL, form);
     yield return w;
     if (w.error != null) {
         print(w.error); //if there is an error, tell us
     }
     else {
         print("League Check 1");
         LinII = w.text; //here we return the data our PHP told us
         print (w.text);
         Lin = LinI + LinII;
         w.Dispose(); //clear our form in game
         StartCoroutine (LeagueCheck2 ());
     }
 }

在LeagueCheck2内部,它使用LinII从数据库中抓取另一个东西,但它无法找到它,因为它会像这样回来

"支配者"

而不是像这样

"支配者"

所以我的问题是如何让它去除Dominators面前的那个小空间。

我试图解决这个问题

using System;


LinII = String.Trim(w.text);

LinII = w.text;

LinII.Trim();

LinII.Replace(" ","");


void Timer(){

LinII.Trim();

}

//In the IEnumator LeagueCheck();

Lin = LinI + LinII;
w.Dispose(); //clear our form in game
Trimer();
StartCoroutine (LeagueCheck2 ());

1 个答案:

答案 0 :(得分:2)

如果w.textLinII是字符串

,这应该有效
if (w.error != null) {
     print(w.error); //if there is an error, tell us
 }
 else {
     print("League Check 1");
     LinII = w.text.Trim(); //here we return the data our PHP told us
     print (LinII );
     Lin = LinI + LinII;
     w.Dispose(); //clear our form in game
     StartCoroutine (LeagueCheck2 ());
 }