当前位置:网站首页>格式化代码缩进的小技巧
格式化代码缩进的小技巧
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会帮忙处理缩进和括号换行的地方了。
大功告成!
平时遇到这种情况,大家是怎么处理的呢?欢迎讨论~
边栏推荐
- network issue?Service packet loss?This is enough
- Come, come, let you understand how Cocos Creator reads and writes JSON files
- 浏览器存储WebStorage
- docker部署完mysql无法连接
- 从“双卡双待“到”双通“,vivo率先推动DSDA架构落地
- Next-Generation Parsing Technology - Cloud Parsing
- Four ways to obtain Class objects through reflection
- 干货!教您使用工业树莓派结合CODESYS配置EtherCAT主站
- From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
- 设置文本向两边居中展示
猜你喜欢

el-progress implements different colors of the progress bar

System basics - study notes (some command records)

selenium学习

DevOps process demo (practical record)

The future of cloud gaming

transport layer protocol

人人AI(吴恩达系列)

config.js related configuration summary

Problems encountered in installing Yolo3 target detection module in Autoware

初识网页与浏览器
随机推荐
Q 2020, the latest senior interview Laya soul, do you know?
selenium learning
Vim tutorial: vimtutor
H5 的浏览器存储
[ingress]-ingress exposes services using tcp port
From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
Met with the browser page
NB-IOT智能云家具项目系列实站
[问题已处理]-jenkins流水线checkout超时
Nacos配置服务的源码解析(全)
input detailed file upload
跨域的十种解决方案详解(总结)
docker部署完mysql无法连接
七种让盒子水平垂直居中的方法
sql server duplicate values are counted after
document.querySelector()方法
reduce()方法的学习和整理
D39_Eulerian Angles and Quaternions
Quick question and quick answer - FAQ of Tencent Cloud Server
深夜小酌,50道经典SQL题,真香~