我在swift中使用\ t进行显示时尝试缩进数据,但它不起作用

时间:2016-09-30 01:33:49

标签: ios arrays swift xcode7

我正在尝试打印()两个数组,而不是在每个数字之间显示一个\ t(tab)的行。
它显示在一列而没有\ t。
不确定我做错了什么。

<table class="numAlpha" border="1">
<tr>
<th bgcolor="#ff9999"></th>
<th class="alpha a" bgcolor="#5588bb">a</th>
<th class="alpha b" bgcolor="#5588bb">b</th>
<th class="alpha c" bgcolor="#5588bb">c</th>
<th class="alpha d" bgcolor="#5588bb">d</th>
<th class="alpha e" bgcolor="#5588bb">e</th>
</tr>
<tr>
<td class="num 1" bgcolor="#5588bb">1</td>
</tr>
<tr>
<td class="num 2" bgcolor="#5588bb">2</td>
</tr>
<tr>
<td class="num 3" bgcolor="#5588bb">3</td>
</tr>
<tr>
<td class="num 4" bgcolor="#5588bb">4</td>
</tr>
<tr>
<td class="num 5" bgcolor="#5588bb">5</td>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

结果如下

2
3
4
5
6
7
8
9
10个
11个
12

=============================================== ===

4
2
7
4
21个
18个
14个
13个
6
10个
2

感谢您的帮助,我是编程新手。

2 个答案:

答案 0 :(得分:1)

Swift'print()'函数默认添加换行符。尝试

public async Task ReInitSpi() { _spi.Dispose(); //Here is important. try { if (settings.ChipSelectLine == 0) { settings = new SpiConnectionSettings(1); //CS1 } else { settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE); //CS0 } settings.ClockFrequency = 1000000; settings.Mode = SpiMode.Mode0; String spiDeviceSelector = SpiDevice.GetDeviceSelector(); IReadOnlyList<DeviceInformation> devices = await DeviceInformation.FindAllAsync(spiDeviceSelector); _spi = await SpiDevice.FromIdAsync(devices[0].Id, settings); } /* If initialization fails, display the exception and stop running */ catch (Exception ex) { throw new Exception("SPI Initialization Failed", ex); } }

这使'print()'在行的末尾添加一个空字符串,而不是换行符。你也可以尝试:

    await mfrc.ReInitSpi();

    var writeBuffer = new byte[] { 0x55, 0xaa };

    mfrc._spi.Write(writeBuffer);

...这会在行尾添加一个标签。

答案 1 :(得分:1)

以下是尝试此代码的简单方法..

 let dicePossibleNum : NSArray = ["1","2", "3","4","5","6", "7","8","9","10", "11","12",]
 let totalcount : Int = dicePossibleNum.count as Int

 for j in 0..<totalcount {
      print("Hello", dicePossibleNum[j],"\t")
 }

输出:

Hello 1     
Hello 2     
Hello 3     
Hello 4     
Hello 5     
Hello 6     
Hello 7     
Hello 8     
Hello 9     
Hello 10    
Hello 11    
Hello 12