我有两个字符串:
using UnityEngine;
using System.Collections;
public class Slime: MonoBehaviour
{
Transform player; // Ref to the player's position.
NavMeshAgent nav; // Ref to the nav mesh agent.
void Awake ()
{
// Set up the references.
player = GameObject.FindGameObjectWithTag ("Player").transform;
nav = GetComponent <NavMeshAgent> ();
}
void Update ()
{
//Here it would be nice to add a stop condition, like when the player is dead or when it is out of range
ChasePlayer();
}
void ChasePlayer() {
nav.SetDestination (player.position);
Debug.Log ("Chasing player");
}
}
想要将两个字符串连接成一个没有重复的字符串。
预期输出:
float dist = Vector3.Distance(player.position, transform.position)
if(dist < 10.0)
{
ChasePlayer();
}
答案 0 :(得分:3)
您可以使用 STRING_SPLIT()
功能和DISTINCT
作为
DECLARE @str1 varchar(max) = '[First Name],[Last Name],[Middle Name]';
DECLARE @str2 varchar(max) = '[First Name],[Pin Code],[Address],[Last Name]';
SELECT DISTINCT *
FROM STRING_SPLIT(@Str1 +','+ @Str2, ',');
或
DECLARE @str1 varchar(max) = '[First Name],[Last Name],[Middle Name]';
DECLARE @str2 varchar(max) = '[First Name],[Pin Code],[Address],[Last Name]';
SELECT DISTINCT *
FROM STRING_SPLIT(CONCAT(@Str1, ',', @Str2), ',');
将其作为一行
declare @result varchar(max) = '';
SELECT @result = @result + value
FROM STRING_SPLIT(CONCAT(@Str1, ',', @Str2), ',')
group by value;
SELECT @result;
并且由于您正在使用SQL Server 2008,因此需要创建自己的函数,例如this one here。