---
title: "Assign blank if String is NULL in Objective-C"  
description: "Assign blank if String is NULL in Objective-C"  
author: "Anonymous User"  
published: 2015-12-07  
updated: 2015-12-08  
canonical: https://www.mindstick.com/forum/33694/assign-blank-if-string-is-null-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Assign blank if String is NULL in Objective-C

I am new in [iOS](https://www.mindstick.com/articles/12222/core-data-and-how-to-use-it-in-ios-objective-c) [app development](https://www.mindstick.com/services/mobile-app-development). I want to [print](https://www.mindstick.com/blog/301752/types-of-3d-printing-technology) [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) if string [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) is [null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp).\
I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):(C#)

```
strObj = strObj??string.Empty;
```

In this code if strObj is null, [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) of string.Empty (for ex: string: **""**) will be assigned.\
So how can I achieve this in Objective-C?

## Replies

### Reply by Tarun Kumar

You can check null string like my example, I am checking first name and last name if any one is not available then it will not assign in personName. Use it as your need;\
Here is my example:

```
NSString *personName;if(person.firstName.lenght !=0 && person.lastName.length !=0)   personName = [[NSString alloc] initWithFormat:@"%@ %@", person.firstName, person.lastName];else if(person.lastName.length == 0)   personName = person.firstName;else   personName = person.lastName;
```


---

Original Source: https://www.mindstick.com/forum/33694/assign-blank-if-string-is-null-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
