当前位置:网站首页>U++ 迭代 排序 查询 学习笔记
U++ 迭代 排序 查询 学习笔记
2022-06-22 13:22:00 【是秃头的兔子呀】
迭代
AUTO:
FString JoinedStr;
for (auto& Str : StrArr)
{
JoinedStr += Str;
JoinedStr += TEXT(" ");
}
// JoinedStr == "Hello Brave World of Tomorrow ! "Index:
for (int32 Index = 0; Index != StrArr.Num(); ++Index)
{
JoinedStr += StrArr[Index];
JoinedStr += TEXT(" ");
}Iterator:
for (auto It = StrArr.CreateConstIterator(); It; ++It)
{
JoinedStr += *It;
JoinedStr += TEXT(" ");
}排序
Sort:
StrArr.Sort();
// StrArr == ["!","Brave","Hello","of","Tomorrow","World"]Lambda声明排序规则(非稳定排序,Sort为快排+堆排+插排(根据快排拆开的排序深度进行选择用快排还是堆排还是插排,这里不细讲,感兴趣可以去看sort的源码实现)):
StrArr.Sort([](const FString& A, const FString& B) {
return A.Len() < B.Len();
});
// StrArr == ["!","of","Hello","Brave","World","Tomorrow"]堆排序使用Lambda声明排序规则(稳定排序):
StrArr.HeapSort([](const FString& A, const FString& B) {
return A.Len() < B.Len();
});
// StrArr == ["!","of","Hello","Brave","World","Tomorrow"]稳定排序(StableSort)使用Lambda申明排序规则:
StrArr.StableSort([](const FString& A, const FString& B) {
return A.Len() < B.Len();
});
// StrArr == ["!","of","Brave","Hello","World","Tomorrow"]查询
Num():
int32 Count = StrArr.Num();
// Count == 6GetData():个人猜测是运算符重载然后进行for循环赋值
FString* StrPtr = StrArr.GetData();
// StrPtr[0] == "!"
// StrPtr[1] == "of"
// ...
// StrPtr[5] == "Tomorrow"
// StrPtr[6] - undefined behaviorGetTypeSize():访问元素所占几byte
uint32 ElementSize = StrArr.GetTypeSize();
// ElementSize == sizeof(FString)运算符重载operator[]:能够获取FString *类型的下标内容
FString Elem1 = StrArr[1];
// Elem1 == "of"isValidIndex(int):传递无效索引(小于 0 或大于或等于 Num())将导致运行时错误。
bool bValidM1 = StrArr.IsValidIndex(-1);
bool bValid0 = StrArr.IsValidIndex(0);
bool bValid5 = StrArr.IsValidIndex(5);
bool bValid6 = StrArr.IsValidIndex(6);
// bValidM1 == false
// bValid0 == true
// bValid5 == true
// bValid6 == falseToUpper():
StrArr[3] = StrArr[3].ToUpper();
// StrArr == ["!","of","Brave","HELLO","World","Tomorrow"]Last() & Top() & Last(int) & Top(int):这两个用处是一样的,都是从数组最后一位为数组开端
FString ElemEnd = StrArr.Last();
FString ElemEnd0 = StrArr.Last(0);
FString ElemEnd1 = StrArr.Last(1);
FString ElemTop = StrArr.Top();
// ElemEnd == "Tomorrow"
// ElemEnd0 == "Tomorrow"
// ElemEnd1 == "World"
// ElemTop == "Tomorrow"Contain(value):数组是否包含value值
bool bHello = StrArr.Contains(TEXT("Hello"));
bool bGoodbye = StrArr.Contains(TEXT("Goodbye"));
// bHello == true
// bGoodbye == false Find(value):我们可以使用Find函数族找到元素。要检查元素是否存在并返回其索引。
int32 Index;
if (StrArr.Find(TEXT("Hello"), Index))
{
// Index == 3
}FindLast(value):如果有重复的元素,而我们想要找到最后一个元素的索引。
int32 IndexLast;
if (StrArr.FindLast(TEXT("Hello"), IndexLast))
{
// IndexLast == 3, because there aren't any duplicates
}Find与FIndLast若没有找到指定值会返回特殊返回值(INDEX_NONE):
int32 Index2 = StrArr.Find(TEXT("Hello"));
int32 IndexLast2 = StrArr.FindLast(TEXT("Hello"));
int32 IndexNone = StrArr.Find(TEXT("None"));
// Index2 == 3
// IndexLast2 == 3
// IndexNone == INDEX_NONE IndexOfByKey(value):IndexOfByKey适用于operator==(ElementType, KeyType)存在的任何键类型。IndexOfByKey将返回第一个找到的元素的索引,或者INDEX_NONE如果没有找到元素:
int32 Index = StrArr.IndexOfByKey(TEXT("Hello"));
// Index == 3
边栏推荐
- bochs 软件使用记录
- Struggle, programmer chapter 50: a bosom friend in the sea
- Cat agile team coaching workshops - August 20
- 数据采集之:巧用布隆过滤器提取数据摘要
- After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-5
- What is the difference between Z-score and deltf/f?
- 11 方法引用和构造器应用
- Fight, programmer -- Chapter 42 will draw a bow like a full moon, look northwest and shoot Sirius
- CVE-2022-22965複現
- C language student management system (open source)
猜你喜欢

Verification code is the natural enemy of automation? See how the great God solved it

擴散模型又殺瘋了!這一次被攻占的領域是...

拜登簽署兩項旨在加强政府網絡安全的新法案

【毕业设计】基于半监督学习和集成学习的情感分析研究

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

Installing and using protobuf-c

Chip silicon and streaming technology

一文彻底弄懂工厂模式(Factory)

C # WinForm photo album function, picture zooming, dragging, preview Pagination

CVE-2022-22965复现
随机推荐
JasperReport报表生成工具的基本使用和常见问题
If you want to know the stock account opening discount link, how do you know? Is it safe to open an account online?
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
JS advanced programming version 4: learning iterators
Biden signe deux nouvelles lois visant à renforcer la cybersécurité du Gouvernement
Thoroughly understand the builder mode (builder)
Closure of groovy
D damage and safety
Basic usage and FAQs of jasperreport report report generation tool
Cve-2022-22965 reappearance
芯片硅片与流片技术
嵌入式中的强符号和弱符号是什么?
C language student management system (open source)
一文彻底弄懂工厂模式(Factory)
How to implement interface exception scenario testing? Exploration of test methods and implementation of test tools
Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things
Chengdu test equipment development_ Array introduction of C language for single chip microcomputer
Biden signs two new laws aimed at strengthening government cyber security
OpenVINO CPU加速调研
Lisez ceci pour vous apprendre à jouer avec la cible de test de pénétration vulnhub - driftingblues - 5