当前位置:网站首页>格式化代码缩进的小技巧
格式化代码缩进的小技巧
2022-08-05 05:25:00 【ProfSnail】
最近这段日子经常混迹于问答板块回答问题,发现了一点小问题。
一些朋友在提问的时候放上来的代码是没有缩进的;或者编程格式不太美观,经常看着看着就迷醉其中了。
提问的兄弟因为自己比较着急,赶紧放上来了一段代码。
自己在这边帮他回答问题,看着代码,也相当着急。今天无意间又发现了一段没有缩进的代码,正好以提问的方式来分享一波。
我简单拿一个这两天帮忙处理的C语言的小程序举例子。我把他变为了无缩进的格式。
BTree createTree(char s[]) {BTNode *p;BTNode *rt;BTNode *lchild, *rchild, parent;stack S;p = (BTNode * )malloc(sizeof(BTNode));p->lchild = NULL;p->rchild = NULL;p->data = s[0];S.push§;rt = p;for(int i = 1; s[i] != ‘\0’; i++){if(‘A’ <= s[i] && s[i] <= ‘Z’) {p = (Node ) malloc(sizeof(Node));p->data = s[i];p->lchild = NULL;p->rchild = NULL;S.pop();S.push§;}if(s[i] == ‘(’) {S.push(NULL);}if(s[i] == ‘,’) {S.push(NULL);}if(s[i] == ‘)’) {rchild = S.top();S.pop();lchild = S.top();S.pop();parent = S.top();S.pop();parent->lchild = lchild;parent->rchild = rchild;S.push(parent);}}return rt;}
这段代码看着就不太想管了,但是想想还是管一管吧。最好用的方法就是将这段代码复制下来,粘贴到VisualStudio里面。
但是对于全部没有空行的代码,VS也处理不了。需要先用Sublime Text处理一下。
Sublime Text Ctrl + H 调出替换界面。搜索分号,将所有的分号替换为分号加换行符(换行符可以使用Ctrl+Enter打出来)。
接下来把这段SublimeText中的代码复制到VisualStudio里面就可以了,VisualStudio会帮忙处理缩进和括号换行的地方了。
大功告成!
平时遇到这种情况,大家是怎么处理的呢?欢迎讨论~
边栏推荐
- config.js related configuration summary
- document.querySelector()方法
- 干货!教您使用工业树莓派结合CODESYS配置EtherCAT主站
- DevOps process demo (practical record)
- reduce()方法的学习和整理
- What?CDN cache acceleration only works for accelerating static content?
- selenium学习
- Operation and maintenance engineer, come and pick up the wool
- What should I do if the SSL certificate prompts that it is expired or invalid?
- What is the website ICP record?
猜你喜欢
设置文本向两边居中展示
Nacos集群的搭建过程详解
Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive
干货!教您使用工业树莓派结合CODESYS配置EtherCAT主站
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
DisabledDate date picker datePicker
Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
DevOps流程demo(实操记录)
Into the pre-service, thought they play so flowers
Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"
随机推荐
js判断文字是否超过区域
H5 的浏览器存储
One-arm routing experiment and three-layer switch experiment
D39_Vector
Shadowless Cloud Desktop
sql server 重复值在后面计数
单臂路由实验和三层交换机实验
初识网页与浏览器
浏览器兼容汇总
Mina断线重连
Insight into the general trend of the Internet, after reading this article, you will have a thorough understanding of Chinese domain names
What are some things that you only know when you do operation and maintenance?
What is Alibaba Cloud Express Beauty Station?
Difference between link and @improt
从“双卡双待“到”双通“,vivo率先推动DSDA架构落地
config.js related configuration summary
Configuration of routers and static routes
vs2017关于函数命名方面的注意事项
Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images
Dry!Teach you to use industrial raspberries pie combining CODESYS configuration EtherCAT master station