本文介绍了斯威夫特:怎么加偏移的memcpy(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何增加抵消阵列的memcpy(...)调用?

How to add offset for array for memcpy(...) invocation?

字符串的数组:

var source = ["a","b","c","d"]
var dest = [String](count:n, repeatedValue: "")
memcpy(&dest, source, UInt(2 * sizeof(String))

此副本[A,B]到dest。很明显。
我怎样才能复制[B,C]

This copy ["a","b"] to dest. I'ts obvious.How can i copy ["b", "c"] ?

推荐答案

不要在对象使用的memcpy或其他低级别C的运营商。这不会的原因很​​多工作。

Do not use memcpy or other low-level "C" operators on objects. That will not work for many reasons.

使用切片运算符:

var source = ["a","b","c","d"]
var dest = Array(source[1...2])
println("dest: \(dest)")

输出:

DEST:[B,C]

统一code是正确处理:

Unicode is handled correctly:

这篇关于斯威夫特:怎么加偏移的memcpy(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:41