2015-04-30 5 views
2

enter image description hereПочему эта строка приводит к разрыву развязки в единстве?

При имени пользователя (середина), почему имя пользователя имеет одну строку пробела?

Я написал код, как

public void SetHighInfo() 
{ 
    var high = HighScore.Instance; 
    rankText.text = ""; 
    nameText.text = ""; 
    scoreText.text = ""; 
    for (int i = 0; i < high.scoreInfo.Count; i++) 
    { 
     rankText.text += "" + high.scoreInfo[i].rank + "\n"; 
     nameText.text += high.scoreInfo[i].name+"\n"; 
     scoreText.text += "" + high.scoreInfo[i].score + "\n"; 
    } 
} 

Как и выше, я использовал только «\ п» один раз в части имени. Но результат показывает, как использовать дважды \ n.

Почему? Как исправить? Спасибо.

+0

Межстрочный интервал 'nameText' задан иначе, чем другие тексты? У имен уже есть '' \ n "" случайно? –

+0

Какова структура ваших элементов пользовательского интерфейса и каковы их свойства? –

+0

Кроме того, почему вы добавляете пустые строки для ранжирования и оценки? –

ответ

0

Я проверил исходные данные сам имеет новую строку после окончания имени.

Так что код был таким, может быть, feof, fgets принял изменения в строке.

<?php 
function DeleteOld($table){ //Delete all entries from a table 
    $sql = "TRUNCATE TABLE $table"; //truncate keeps the structure of the sql table 
    $result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
} 
function RePopulate($table,$names,$min,$max,$count){ //Repopulate With Dummy Entries 
    //Repopulate table with '$count' number of entries 
    for($i = 1; $i <= $count; $i++){ 
     $name = $names[mt_rand(0,Count($names) - 1)]; //Get a random name 
     $score = floor(mt_rand($min,$max)); //Get a random score 
     $date = strtotime(date("Y-m-d")); 
     $sql = "INSERT INTO $table(name,score,date) 
     VALUES('$name','$score','$date')"; 
     $result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
    } 
    //Now update our table, by ordering it by descending score 
    $sql = "ALTER TABLE $table ORDER BY score DESC,id DESC"; 
    $result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
} 

include('ServerConnect.php'); 
$connection = Connect();//Attempt to connect to MYSQL server & dataBase 

//Get variables from user 
$table = $_POST['table']; 
$mode = $_POST['mode']; 
$userCount = $_POST['count']; 
$minScore = $_POST['min']; 
$maxScore = $_POST['max']; 

//Grab all good names we will use 
if($mode == 'Reset'){ 
    $names[0] = 'Names Array'; 
    $index = 0; 
    $file = fopen("GoodNames.txt","r") or exit("No Such File"); //Open goodnames.txt file 
    while(!feof($file)){ //Read each line and Add 
     $names[$index] = fgets($file); // add all names to an array 
     $index++; 
    } 
} 
DeleteOld($table); //Delete all entries from chosen table 
if($mode == 'Reset'){RePopulate($table,$names,$minScore,$maxScore,$userCount);} //Repopulate the table if we are in reset mode 
echo 'Scores Reset'; 
?> 

 Смежные вопросы

  • Нет связанных вопросов^_^